| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2014 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 |  | 
 | 17 | #include "code_generator_x86.h" | 
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 |  | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" | 
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" | 
| Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" | 
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 25 | #include "intrinsics.h" | 
 | 26 | #include "intrinsics_x86.h" | 
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" | 
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 29 | #include "thread.h" | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | #include "utils/assembler.h" | 
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | #include "utils/x86/assembler_x86.h" | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | #include "utils/x86/managed_register_x86.h" | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 |  | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> | 
 | 38 | class GcRoot; | 
 | 39 |  | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace x86 { | 
 | 41 |  | 
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = EAX; | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 44 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 45 |  | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 46 | static constexpr int kC2ConditionMask = 0x400; | 
 | 47 |  | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 48 | static constexpr int kFakeReturnRegister = Register(8); | 
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 49 |  | 
| Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 50 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 51 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 52 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 53 | class NullCheckSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 54 |  public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 55 |   explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 56 |  | 
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 57 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 58 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 59 |     __ Bind(GetEntryLabel()); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 60 |     if (instruction_->CanThrowIntoCatchBlock()) { | 
 | 61 |       // Live registers will be restored in the catch block if caught. | 
 | 62 |       SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
 | 63 |     } | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 64 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), | 
 | 65 |                                instruction_, | 
 | 66 |                                instruction_->GetDexPc(), | 
 | 67 |                                this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 68 |     CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 69 |   } | 
 | 70 |  | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 71 |   bool IsFatal() const OVERRIDE { return true; } | 
 | 72 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 73 |   const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } | 
 | 74 |  | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 |  private: | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 |   DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); | 
 | 77 | }; | 
 | 78 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 79 | class DivZeroCheckSlowPathX86 : public SlowPathCode { | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 80 |  public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 81 |   explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 82 |  | 
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 83 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 84 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 85 |     __ Bind(GetEntryLabel()); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 86 |     if (instruction_->CanThrowIntoCatchBlock()) { | 
 | 87 |       // Live registers will be restored in the catch block if caught. | 
 | 88 |       SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
 | 89 |     } | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 90 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), | 
 | 91 |                                instruction_, | 
 | 92 |                                instruction_->GetDexPc(), | 
 | 93 |                                this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 94 |     CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 95 |   } | 
 | 96 |  | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 97 |   bool IsFatal() const OVERRIDE { return true; } | 
 | 98 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 99 |   const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } | 
 | 100 |  | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 101 |  private: | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 |   DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); | 
 | 103 | }; | 
 | 104 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 105 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 |  public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 107 |   DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) | 
 | 108 |       : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 |  | 
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 110 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 |     __ Bind(GetEntryLabel()); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 112 |     if (is_div_) { | 
 | 113 |       __ negl(reg_); | 
 | 114 |     } else { | 
 | 115 |       __ movl(reg_, Immediate(0)); | 
 | 116 |     } | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 117 |     __ jmp(GetExitLabel()); | 
 | 118 |   } | 
 | 119 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 120 |   const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } | 
 | 121 |  | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 122 |  private: | 
 | 123 |   Register reg_; | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 124 |   bool is_div_; | 
 | 125 |   DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 126 | }; | 
 | 127 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 128 | class BoundsCheckSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 |  public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 130 |   explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 131 |  | 
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 132 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 133 |     LocationSummary* locations = instruction_->GetLocations(); | 
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 134 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 135 |     __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 136 |     // We're moving two locations to locations that could overlap, so we need a parallel | 
 | 137 |     // move resolver. | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 138 |     if (instruction_->CanThrowIntoCatchBlock()) { | 
 | 139 |       // Live registers will be restored in the catch block if caught. | 
 | 140 |       SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
 | 141 |     } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 142 |     InvokeRuntimeCallingConvention calling_convention; | 
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 143 |     x86_codegen->EmitParallelMoves( | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 144 |         locations->InAt(0), | 
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 145 |         Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 146 |         Primitive::kPrimInt, | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 147 |         locations->InAt(1), | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 148 |         Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
 | 149 |         Primitive::kPrimInt); | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 150 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), | 
 | 151 |                                instruction_, | 
 | 152 |                                instruction_->GetDexPc(), | 
 | 153 |                                this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 154 |     CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 155 |   } | 
 | 156 |  | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 157 |   bool IsFatal() const OVERRIDE { return true; } | 
 | 158 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 159 |   const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } | 
 | 160 |  | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 161 |  private: | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 162 |   DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); | 
 | 163 | }; | 
 | 164 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 165 | class SuspendCheckSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 166 |  public: | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 167 |   SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 168 |       : SlowPathCode(instruction), successor_(successor) {} | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 169 |  | 
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 170 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 171 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 172 |     __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 173 |     SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 174 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), | 
 | 175 |                                instruction_, | 
 | 176 |                                instruction_->GetDexPc(), | 
 | 177 |                                this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 178 |     CheckEntrypointTypes<kQuickTestSuspend, void, void>(); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 179 |     RestoreLiveRegisters(codegen, instruction_->GetLocations()); | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 180 |     if (successor_ == nullptr) { | 
 | 181 |       __ jmp(GetReturnLabel()); | 
 | 182 |     } else { | 
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 183 |       __ jmp(x86_codegen->GetLabelOf(successor_)); | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 184 |     } | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 185 |   } | 
 | 186 |  | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 187 |   Label* GetReturnLabel() { | 
 | 188 |     DCHECK(successor_ == nullptr); | 
 | 189 |     return &return_label_; | 
 | 190 |   } | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 191 |  | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 192 |   HBasicBlock* GetSuccessor() const { | 
 | 193 |     return successor_; | 
 | 194 |   } | 
 | 195 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 196 |   const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } | 
 | 197 |  | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 198 |  private: | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 199 |   HBasicBlock* const successor_; | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 200 |   Label return_label_; | 
 | 201 |  | 
 | 202 |   DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); | 
 | 203 | }; | 
 | 204 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 205 | class LoadStringSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 206 |  public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 207 |   explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 208 |  | 
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 209 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 210 |     LocationSummary* locations = instruction_->GetLocations(); | 
 | 211 |     DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
 | 212 |  | 
 | 213 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
 | 214 |     __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 215 |     SaveLiveRegisters(codegen, locations); | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 216 |  | 
 | 217 |     InvokeRuntimeCallingConvention calling_convention; | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 218 |     const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); | 
 | 219 |     __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 220 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), | 
 | 221 |                                instruction_, | 
 | 222 |                                instruction_->GetDexPc(), | 
 | 223 |                                this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 224 |     CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 225 |     x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 226 |     RestoreLiveRegisters(codegen, locations); | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 227 |  | 
 | 228 |     __ jmp(GetExitLabel()); | 
 | 229 |   } | 
 | 230 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 231 |   const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } | 
 | 232 |  | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 233 |  private: | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 234 |   DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); | 
 | 235 | }; | 
 | 236 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 237 | class LoadClassSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 238 |  public: | 
 | 239 |   LoadClassSlowPathX86(HLoadClass* cls, | 
 | 240 |                        HInstruction* at, | 
 | 241 |                        uint32_t dex_pc, | 
 | 242 |                        bool do_clinit) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 243 |       : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 |     DCHECK(at->IsLoadClass() || at->IsClinitCheck()); | 
 | 245 |   } | 
 | 246 |  | 
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 247 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 248 |     LocationSummary* locations = at_->GetLocations(); | 
 | 249 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
 | 250 |     __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 251 |     SaveLiveRegisters(codegen, locations); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 252 |  | 
 | 253 |     InvokeRuntimeCallingConvention calling_convention; | 
 | 254 |     __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 255 |     x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) | 
 | 256 |                                           : QUICK_ENTRY_POINT(pInitializeType), | 
 | 257 |                                at_, dex_pc_, this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 258 |     if (do_clinit_) { | 
 | 259 |       CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); | 
 | 260 |     } else { | 
 | 261 |       CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); | 
 | 262 |     } | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 263 |  | 
 | 264 |     // Move the class to the desired location. | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 265 |     Location out = locations->Out(); | 
 | 266 |     if (out.IsValid()) { | 
 | 267 |       DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); | 
 | 268 |       x86_codegen->Move32(out, Location::RegisterLocation(EAX)); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 |     } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 270 |  | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 271 |     RestoreLiveRegisters(codegen, locations); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 272 |     __ jmp(GetExitLabel()); | 
 | 273 |   } | 
 | 274 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 275 |   const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } | 
 | 276 |  | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 277 |  private: | 
 | 278 |   // The class this slow path will load. | 
 | 279 |   HLoadClass* const cls_; | 
 | 280 |  | 
 | 281 |   // The instruction where this slow path is happening. | 
 | 282 |   // (Might be the load class or an initialization check). | 
 | 283 |   HInstruction* const at_; | 
 | 284 |  | 
 | 285 |   // The dex PC of `at_`. | 
 | 286 |   const uint32_t dex_pc_; | 
 | 287 |  | 
 | 288 |   // Whether to initialize the class. | 
 | 289 |   const bool do_clinit_; | 
 | 290 |  | 
 | 291 |   DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); | 
 | 292 | }; | 
 | 293 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 294 | class TypeCheckSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 295 |  public: | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 296 |   TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 297 |       : SlowPathCode(instruction), is_fatal_(is_fatal) {} | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 298 |  | 
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 299 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 300 |     LocationSummary* locations = instruction_->GetLocations(); | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 301 |     Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) | 
 | 302 |                                                         : locations->Out(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 303 |     DCHECK(instruction_->IsCheckCast() | 
 | 304 |            || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 305 |  | 
 | 306 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
 | 307 |     __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 308 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 309 |     if (!is_fatal_) { | 
 | 310 |       SaveLiveRegisters(codegen, locations); | 
 | 311 |     } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 312 |  | 
 | 313 |     // We're moving two locations to locations that could overlap, so we need a parallel | 
 | 314 |     // move resolver. | 
 | 315 |     InvokeRuntimeCallingConvention calling_convention; | 
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 316 |     x86_codegen->EmitParallelMoves( | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 317 |         locations->InAt(1), | 
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 318 |         Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 319 |         Primitive::kPrimNot, | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 320 |         object_class, | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 321 |         Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
 | 322 |         Primitive::kPrimNot); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 323 |  | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 324 |     if (instruction_->IsInstanceOf()) { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 325 |       x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), | 
 | 326 |                                  instruction_, | 
 | 327 |                                  instruction_->GetDexPc(), | 
 | 328 |                                  this); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 329 |       CheckEntrypointTypes< | 
 | 330 |           kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 331 |     } else { | 
 | 332 |       DCHECK(instruction_->IsCheckCast()); | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 333 |       x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), | 
 | 334 |                                  instruction_, | 
 | 335 |                                  instruction_->GetDexPc(), | 
 | 336 |                                  this); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 337 |       CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 |     } | 
 | 339 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 340 |     if (!is_fatal_) { | 
 | 341 |       if (instruction_->IsInstanceOf()) { | 
 | 342 |         x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); | 
 | 343 |       } | 
 | 344 |       RestoreLiveRegisters(codegen, locations); | 
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 345 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 346 |       __ jmp(GetExitLabel()); | 
 | 347 |     } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 348 |   } | 
 | 349 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 350 |   const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 |   bool IsFatal() const OVERRIDE { return is_fatal_; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 352 |  | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 |  private: | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 354 |   const bool is_fatal_; | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 355 |  | 
 | 356 |   DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); | 
 | 357 | }; | 
 | 358 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 359 | class DeoptimizationSlowPathX86 : public SlowPathCode { | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 360 |  public: | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 361 |   explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 362 |     : SlowPathCode(instruction) {} | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 363 |  | 
 | 364 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 365 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 366 |     __ Bind(GetEntryLabel()); | 
 | 367 |     SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 368 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), | 
 | 369 |                                instruction_, | 
 | 370 |                                instruction_->GetDexPc(), | 
 | 371 |                                this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 372 |     CheckEntrypointTypes<kQuickDeoptimize, void, void>(); | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 373 |   } | 
 | 374 |  | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 375 |   const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } | 
 | 376 |  | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 377 |  private: | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 |   DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); | 
 | 379 | }; | 
 | 380 |  | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 381 | class ArraySetSlowPathX86 : public SlowPathCode { | 
 | 382 |  public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 383 |   explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 384 |  | 
 | 385 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
 | 386 |     LocationSummary* locations = instruction_->GetLocations(); | 
 | 387 |     __ Bind(GetEntryLabel()); | 
 | 388 |     SaveLiveRegisters(codegen, locations); | 
 | 389 |  | 
 | 390 |     InvokeRuntimeCallingConvention calling_convention; | 
 | 391 |     HParallelMove parallel_move(codegen->GetGraph()->GetArena()); | 
 | 392 |     parallel_move.AddMove( | 
 | 393 |         locations->InAt(0), | 
 | 394 |         Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
 | 395 |         Primitive::kPrimNot, | 
 | 396 |         nullptr); | 
 | 397 |     parallel_move.AddMove( | 
 | 398 |         locations->InAt(1), | 
 | 399 |         Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
 | 400 |         Primitive::kPrimInt, | 
 | 401 |         nullptr); | 
 | 402 |     parallel_move.AddMove( | 
 | 403 |         locations->InAt(2), | 
 | 404 |         Location::RegisterLocation(calling_convention.GetRegisterAt(2)), | 
 | 405 |         Primitive::kPrimNot, | 
 | 406 |         nullptr); | 
 | 407 |     codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); | 
 | 408 |  | 
 | 409 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
 | 410 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), | 
 | 411 |                                instruction_, | 
 | 412 |                                instruction_->GetDexPc(), | 
 | 413 |                                this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 414 |     CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 415 |     RestoreLiveRegisters(codegen, locations); | 
 | 416 |     __ jmp(GetExitLabel()); | 
 | 417 |   } | 
 | 418 |  | 
 | 419 |   const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } | 
 | 420 |  | 
 | 421 |  private: | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 422 |   DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); | 
 | 423 | }; | 
 | 424 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 425 | // Slow path marking an object during a read barrier. | 
 | 426 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { | 
 | 427 |  public: | 
 | 428 |   ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location out, Location obj) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 429 |       : SlowPathCode(instruction), out_(out), obj_(obj) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 430 |     DCHECK(kEmitCompilerReadBarrier); | 
 | 431 |   } | 
 | 432 |  | 
 | 433 |   const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } | 
 | 434 |  | 
 | 435 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
 | 436 |     LocationSummary* locations = instruction_->GetLocations(); | 
 | 437 |     Register reg_out = out_.AsRegister<Register>(); | 
 | 438 |     DCHECK(locations->CanCall()); | 
 | 439 |     DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); | 
 | 440 |     DCHECK(instruction_->IsInstanceFieldGet() || | 
 | 441 |            instruction_->IsStaticFieldGet() || | 
 | 442 |            instruction_->IsArrayGet() || | 
 | 443 |            instruction_->IsLoadClass() || | 
 | 444 |            instruction_->IsLoadString() || | 
 | 445 |            instruction_->IsInstanceOf() || | 
 | 446 |            instruction_->IsCheckCast()) | 
 | 447 |         << "Unexpected instruction in read barrier marking slow path: " | 
 | 448 |         << instruction_->DebugName(); | 
 | 449 |  | 
 | 450 |     __ Bind(GetEntryLabel()); | 
 | 451 |     SaveLiveRegisters(codegen, locations); | 
 | 452 |  | 
 | 453 |     InvokeRuntimeCallingConvention calling_convention; | 
 | 454 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
 | 455 |     x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); | 
 | 456 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), | 
 | 457 |                                instruction_, | 
 | 458 |                                instruction_->GetDexPc(), | 
 | 459 |                                this); | 
 | 460 |     CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); | 
 | 461 |     x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); | 
 | 462 |  | 
 | 463 |     RestoreLiveRegisters(codegen, locations); | 
 | 464 |     __ jmp(GetExitLabel()); | 
 | 465 |   } | 
 | 466 |  | 
 | 467 |  private: | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 468 |   const Location out_; | 
 | 469 |   const Location obj_; | 
 | 470 |  | 
 | 471 |   DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); | 
 | 472 | }; | 
 | 473 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 474 | // Slow path generating a read barrier for a heap reference. | 
 | 475 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { | 
 | 476 |  public: | 
 | 477 |   ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, | 
 | 478 |                                          Location out, | 
 | 479 |                                          Location ref, | 
 | 480 |                                          Location obj, | 
 | 481 |                                          uint32_t offset, | 
 | 482 |                                          Location index) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 483 |       : SlowPathCode(instruction), | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 484 |         out_(out), | 
 | 485 |         ref_(ref), | 
 | 486 |         obj_(obj), | 
 | 487 |         offset_(offset), | 
 | 488 |         index_(index) { | 
 | 489 |     DCHECK(kEmitCompilerReadBarrier); | 
 | 490 |     // If `obj` is equal to `out` or `ref`, it means the initial object | 
 | 491 |     // has been overwritten by (or after) the heap object reference load | 
 | 492 |     // to be instrumented, e.g.: | 
 | 493 |     // | 
 | 494 |     //   __ movl(out, Address(out, offset)); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 495 |     //   codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 496 |     // | 
 | 497 |     // In that case, we have lost the information about the original | 
 | 498 |     // object, and the emitted read barrier cannot work properly. | 
 | 499 |     DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; | 
 | 500 |     DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; | 
 | 501 |   } | 
 | 502 |  | 
 | 503 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
 | 504 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
 | 505 |     LocationSummary* locations = instruction_->GetLocations(); | 
 | 506 |     Register reg_out = out_.AsRegister<Register>(); | 
 | 507 |     DCHECK(locations->CanCall()); | 
 | 508 |     DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); | 
 | 509 |     DCHECK(!instruction_->IsInvoke() || | 
 | 510 |            (instruction_->IsInvokeStaticOrDirect() && | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 511 |             instruction_->GetLocations()->Intrinsified())) | 
 | 512 |         << "Unexpected instruction in read barrier for heap reference slow path: " | 
 | 513 |         << instruction_->DebugName(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 514 |  | 
 | 515 |     __ Bind(GetEntryLabel()); | 
 | 516 |     SaveLiveRegisters(codegen, locations); | 
 | 517 |  | 
 | 518 |     // We may have to change the index's value, but as `index_` is a | 
 | 519 |     // constant member (like other "inputs" of this slow path), | 
 | 520 |     // introduce a copy of it, `index`. | 
 | 521 |     Location index = index_; | 
 | 522 |     if (index_.IsValid()) { | 
 | 523 |       // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. | 
 | 524 |       if (instruction_->IsArrayGet()) { | 
 | 525 |         // Compute the actual memory offset and store it in `index`. | 
 | 526 |         Register index_reg = index_.AsRegister<Register>(); | 
 | 527 |         DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); | 
 | 528 |         if (codegen->IsCoreCalleeSaveRegister(index_reg)) { | 
 | 529 |           // We are about to change the value of `index_reg` (see the | 
 | 530 |           // calls to art::x86::X86Assembler::shll and | 
 | 531 |           // art::x86::X86Assembler::AddImmediate below), but it has | 
 | 532 |           // not been saved by the previous call to | 
 | 533 |           // art::SlowPathCode::SaveLiveRegisters, as it is a | 
 | 534 |           // callee-save register -- | 
 | 535 |           // art::SlowPathCode::SaveLiveRegisters does not consider | 
 | 536 |           // callee-save registers, as it has been designed with the | 
 | 537 |           // assumption that callee-save registers are supposed to be | 
 | 538 |           // handled by the called function.  So, as a callee-save | 
 | 539 |           // register, `index_reg` _would_ eventually be saved onto | 
 | 540 |           // the stack, but it would be too late: we would have | 
 | 541 |           // changed its value earlier.  Therefore, we manually save | 
 | 542 |           // it here into another freely available register, | 
 | 543 |           // `free_reg`, chosen of course among the caller-save | 
 | 544 |           // registers (as a callee-save `free_reg` register would | 
 | 545 |           // exhibit the same problem). | 
 | 546 |           // | 
 | 547 |           // Note we could have requested a temporary register from | 
 | 548 |           // the register allocator instead; but we prefer not to, as | 
 | 549 |           // this is a slow path, and we know we can find a | 
 | 550 |           // caller-save register that is available. | 
 | 551 |           Register free_reg = FindAvailableCallerSaveRegister(codegen); | 
 | 552 |           __ movl(free_reg, index_reg); | 
 | 553 |           index_reg = free_reg; | 
 | 554 |           index = Location::RegisterLocation(index_reg); | 
 | 555 |         } else { | 
 | 556 |           // The initial register stored in `index_` has already been | 
 | 557 |           // saved in the call to art::SlowPathCode::SaveLiveRegisters | 
 | 558 |           // (as it is not a callee-save register), so we can freely | 
 | 559 |           // use it. | 
 | 560 |         } | 
 | 561 |         // Shifting the index value contained in `index_reg` by the scale | 
 | 562 |         // factor (2) cannot overflow in practice, as the runtime is | 
 | 563 |         // unable to allocate object arrays with a size larger than | 
 | 564 |         // 2^26 - 1 (that is, 2^28 - 4 bytes). | 
 | 565 |         __ shll(index_reg, Immediate(TIMES_4)); | 
 | 566 |         static_assert( | 
 | 567 |             sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), | 
 | 568 |             "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); | 
 | 569 |         __ AddImmediate(index_reg, Immediate(offset_)); | 
 | 570 |       } else { | 
 | 571 |         DCHECK(instruction_->IsInvoke()); | 
 | 572 |         DCHECK(instruction_->GetLocations()->Intrinsified()); | 
 | 573 |         DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || | 
 | 574 |                (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) | 
 | 575 |             << instruction_->AsInvoke()->GetIntrinsic(); | 
 | 576 |         DCHECK_EQ(offset_, 0U); | 
 | 577 |         DCHECK(index_.IsRegisterPair()); | 
 | 578 |         // UnsafeGet's offset location is a register pair, the low | 
 | 579 |         // part contains the correct offset. | 
 | 580 |         index = index_.ToLow(); | 
 | 581 |       } | 
 | 582 |     } | 
 | 583 |  | 
 | 584 |     // We're moving two or three locations to locations that could | 
 | 585 |     // overlap, so we need a parallel move resolver. | 
 | 586 |     InvokeRuntimeCallingConvention calling_convention; | 
 | 587 |     HParallelMove parallel_move(codegen->GetGraph()->GetArena()); | 
 | 588 |     parallel_move.AddMove(ref_, | 
 | 589 |                           Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
 | 590 |                           Primitive::kPrimNot, | 
 | 591 |                           nullptr); | 
 | 592 |     parallel_move.AddMove(obj_, | 
 | 593 |                           Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
 | 594 |                           Primitive::kPrimNot, | 
 | 595 |                           nullptr); | 
 | 596 |     if (index.IsValid()) { | 
 | 597 |       parallel_move.AddMove(index, | 
 | 598 |                             Location::RegisterLocation(calling_convention.GetRegisterAt(2)), | 
 | 599 |                             Primitive::kPrimInt, | 
 | 600 |                             nullptr); | 
 | 601 |       codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); | 
 | 602 |     } else { | 
 | 603 |       codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); | 
 | 604 |       __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); | 
 | 605 |     } | 
 | 606 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), | 
 | 607 |                                instruction_, | 
 | 608 |                                instruction_->GetDexPc(), | 
 | 609 |                                this); | 
 | 610 |     CheckEntrypointTypes< | 
 | 611 |         kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); | 
 | 612 |     x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); | 
 | 613 |  | 
 | 614 |     RestoreLiveRegisters(codegen, locations); | 
 | 615 |     __ jmp(GetExitLabel()); | 
 | 616 |   } | 
 | 617 |  | 
 | 618 |   const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } | 
 | 619 |  | 
 | 620 |  private: | 
 | 621 |   Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { | 
 | 622 |     size_t ref = static_cast<int>(ref_.AsRegister<Register>()); | 
 | 623 |     size_t obj = static_cast<int>(obj_.AsRegister<Register>()); | 
 | 624 |     for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { | 
 | 625 |       if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { | 
 | 626 |         return static_cast<Register>(i); | 
 | 627 |       } | 
 | 628 |     } | 
 | 629 |     // We shall never fail to find a free caller-save register, as | 
 | 630 |     // there are more than two core caller-save registers on x86 | 
 | 631 |     // (meaning it is possible to find one which is different from | 
 | 632 |     // `ref` and `obj`). | 
 | 633 |     DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); | 
 | 634 |     LOG(FATAL) << "Could not find a free caller-save register"; | 
 | 635 |     UNREACHABLE(); | 
 | 636 |   } | 
 | 637 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 638 |   const Location out_; | 
 | 639 |   const Location ref_; | 
 | 640 |   const Location obj_; | 
 | 641 |   const uint32_t offset_; | 
 | 642 |   // An additional location containing an index to an array. | 
 | 643 |   // Only used for HArrayGet and the UnsafeGetObject & | 
 | 644 |   // UnsafeGetObjectVolatile intrinsics. | 
 | 645 |   const Location index_; | 
 | 646 |  | 
 | 647 |   DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); | 
 | 648 | }; | 
 | 649 |  | 
 | 650 | // Slow path generating a read barrier for a GC root. | 
 | 651 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { | 
 | 652 |  public: | 
 | 653 |   ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 654 |       : SlowPathCode(instruction), out_(out), root_(root) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 655 |     DCHECK(kEmitCompilerReadBarrier); | 
 | 656 |   } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 657 |  | 
 | 658 |   void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { | 
 | 659 |     LocationSummary* locations = instruction_->GetLocations(); | 
 | 660 |     Register reg_out = out_.AsRegister<Register>(); | 
 | 661 |     DCHECK(locations->CanCall()); | 
 | 662 |     DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 663 |     DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) | 
 | 664 |         << "Unexpected instruction in read barrier for GC root slow path: " | 
 | 665 |         << instruction_->DebugName(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 666 |  | 
 | 667 |     __ Bind(GetEntryLabel()); | 
 | 668 |     SaveLiveRegisters(codegen, locations); | 
 | 669 |  | 
 | 670 |     InvokeRuntimeCallingConvention calling_convention; | 
 | 671 |     CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
 | 672 |     x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); | 
 | 673 |     x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), | 
 | 674 |                                instruction_, | 
 | 675 |                                instruction_->GetDexPc(), | 
 | 676 |                                this); | 
 | 677 |     CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); | 
 | 678 |     x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); | 
 | 679 |  | 
 | 680 |     RestoreLiveRegisters(codegen, locations); | 
 | 681 |     __ jmp(GetExitLabel()); | 
 | 682 |   } | 
 | 683 |  | 
 | 684 |   const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } | 
 | 685 |  | 
 | 686 |  private: | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 687 |   const Location out_; | 
 | 688 |   const Location root_; | 
 | 689 |  | 
 | 690 |   DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); | 
 | 691 | }; | 
 | 692 |  | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 693 | #undef __ | 
| Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 694 | #define __ down_cast<X86Assembler*>(GetAssembler())-> | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 695 |  | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 696 | inline Condition X86Condition(IfCondition cond) { | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 697 |   switch (cond) { | 
 | 698 |     case kCondEQ: return kEqual; | 
 | 699 |     case kCondNE: return kNotEqual; | 
 | 700 |     case kCondLT: return kLess; | 
 | 701 |     case kCondLE: return kLessEqual; | 
 | 702 |     case kCondGT: return kGreater; | 
 | 703 |     case kCondGE: return kGreaterEqual; | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 704 |     case kCondB:  return kBelow; | 
 | 705 |     case kCondBE: return kBelowEqual; | 
 | 706 |     case kCondA:  return kAbove; | 
 | 707 |     case kCondAE: return kAboveEqual; | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 708 |   } | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 709 |   LOG(FATAL) << "Unreachable"; | 
 | 710 |   UNREACHABLE(); | 
 | 711 | } | 
 | 712 |  | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 713 | // Maps signed condition to unsigned condition and FP condition to x86 name. | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 714 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { | 
 | 715 |   switch (cond) { | 
 | 716 |     case kCondEQ: return kEqual; | 
 | 717 |     case kCondNE: return kNotEqual; | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 718 |     // Signed to unsigned, and FP to x86 name. | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 719 |     case kCondLT: return kBelow; | 
 | 720 |     case kCondLE: return kBelowEqual; | 
 | 721 |     case kCondGT: return kAbove; | 
 | 722 |     case kCondGE: return kAboveEqual; | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 723 |     // Unsigned remain unchanged. | 
 | 724 |     case kCondB:  return kBelow; | 
 | 725 |     case kCondBE: return kBelowEqual; | 
 | 726 |     case kCondA:  return kAbove; | 
 | 727 |     case kCondAE: return kAboveEqual; | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 728 |   } | 
 | 729 |   LOG(FATAL) << "Unreachable"; | 
 | 730 |   UNREACHABLE(); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 731 | } | 
 | 732 |  | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 733 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { | 
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 734 |   stream << Register(reg); | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 735 | } | 
 | 736 |  | 
 | 737 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { | 
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 738 |   stream << XmmRegister(reg); | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 739 | } | 
 | 740 |  | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 741 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { | 
 | 742 |   __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); | 
 | 743 |   return kX86WordSize; | 
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 744 | } | 
 | 745 |  | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 746 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { | 
 | 747 |   __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); | 
 | 748 |   return kX86WordSize; | 
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 749 | } | 
 | 750 |  | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 751 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
 | 752 |   __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); | 
 | 753 |   return GetFloatingPointSpillSlotSize(); | 
 | 754 | } | 
 | 755 |  | 
 | 756 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
 | 757 |   __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); | 
 | 758 |   return GetFloatingPointSpillSlotSize(); | 
 | 759 | } | 
 | 760 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 761 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, | 
 | 762 |                                      HInstruction* instruction, | 
 | 763 |                                      uint32_t dex_pc, | 
 | 764 |                                      SlowPathCode* slow_path) { | 
 | 765 |   InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), | 
 | 766 |                 instruction, | 
 | 767 |                 dex_pc, | 
 | 768 |                 slow_path); | 
 | 769 | } | 
 | 770 |  | 
 | 771 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 772 |                                      HInstruction* instruction, | 
 | 773 |                                      uint32_t dex_pc, | 
 | 774 |                                      SlowPathCode* slow_path) { | 
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 775 |   ValidateInvokeRuntime(instruction, slow_path); | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 776 |   __ fs()->call(Address::Absolute(entry_point_offset)); | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 777 |   RecordPcInfo(instruction, dex_pc, slow_path); | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 778 | } | 
 | 779 |  | 
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 780 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 781 |                                    const X86InstructionSetFeatures& isa_features, | 
 | 782 |                                    const CompilerOptions& compiler_options, | 
 | 783 |                                    OptimizingCompilerStats* stats) | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 784 |     : CodeGenerator(graph, | 
 | 785 |                     kNumberOfCpuRegisters, | 
 | 786 |                     kNumberOfXmmRegisters, | 
 | 787 |                     kNumberOfRegisterPairs, | 
 | 788 |                     ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), | 
 | 789 |                                         arraysize(kCoreCalleeSaves)) | 
 | 790 |                         | (1 << kFakeReturnRegister), | 
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 791 |                     0, | 
 | 792 |                     compiler_options, | 
 | 793 |                     stats), | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 794 |       block_labels_(nullptr), | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 795 |       location_builder_(graph, this), | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 796 |       instruction_visitor_(graph, this), | 
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 797 |       move_resolver_(graph->GetArena(), this), | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 798 |       isa_features_(isa_features), | 
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 799 |       method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 800 |       relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 801 |       pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 802 |       simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), | 
 | 803 |       string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 804 |       fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 805 |   // Use a fake return address register to mimic Quick. | 
 | 806 |   AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 807 | } | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 808 |  | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 809 | void CodeGeneratorX86::SetupBlockedRegisters() const { | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 810 |   // Don't allocate the dalvik style register pair passing. | 
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 811 |   blocked_register_pairs_[ECX_EDX] = true; | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 812 |  | 
 | 813 |   // Stack register is always reserved. | 
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 814 |   blocked_core_registers_[ESP] = true; | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 815 |  | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 816 |   UpdateBlockedPairRegisters(); | 
 | 817 | } | 
 | 818 |  | 
 | 819 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { | 
 | 820 |   for (int i = 0; i < kNumberOfRegisterPairs; i++) { | 
 | 821 |     X86ManagedRegister current = | 
 | 822 |         X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); | 
 | 823 |     if (blocked_core_registers_[current.AsRegisterPairLow()] | 
 | 824 |         || blocked_core_registers_[current.AsRegisterPairHigh()]) { | 
 | 825 |       blocked_register_pairs_[i] = true; | 
 | 826 |     } | 
 | 827 |   } | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 828 | } | 
 | 829 |  | 
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 830 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 831 |       : InstructionCodeGenerator(graph, codegen), | 
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 832 |         assembler_(codegen->GetAssembler()), | 
 | 833 |         codegen_(codegen) {} | 
 | 834 |  | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 835 | static dwarf::Reg DWARFReg(Register reg) { | 
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 836 |   return dwarf::Reg::X86Core(static_cast<int>(reg)); | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 837 | } | 
 | 838 |  | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 839 | void CodeGeneratorX86::GenerateFrameEntry() { | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 840 |   __ cfi().SetCurrentCFAOffset(kX86WordSize);  // return address | 
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 841 |   __ Bind(&frame_entry_label_); | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 842 |   bool skip_overflow_check = | 
 | 843 |       IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 844 |   DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); | 
| Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 845 |  | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 846 |   if (!skip_overflow_check) { | 
| Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 847 |     __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 848 |     RecordPcInfo(nullptr, 0); | 
| Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 849 |   } | 
 | 850 |  | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 851 |   if (HasEmptyFrame()) { | 
 | 852 |     return; | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 853 |   } | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 854 |  | 
 | 855 |   for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { | 
 | 856 |     Register reg = kCoreCalleeSaves[i]; | 
 | 857 |     if (allocated_registers_.ContainsCoreRegister(reg)) { | 
 | 858 |       __ pushl(reg); | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 859 |       __ cfi().AdjustCFAOffset(kX86WordSize); | 
 | 860 |       __ cfi().RelOffset(DWARFReg(reg), 0); | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 861 |     } | 
 | 862 |   } | 
 | 863 |  | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 864 |   int adjust = GetFrameSize() - FrameEntrySpillSize(); | 
 | 865 |   __ subl(ESP, Immediate(adjust)); | 
 | 866 |   __ cfi().AdjustCFAOffset(adjust); | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 867 |   __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 868 | } | 
 | 869 |  | 
 | 870 | void CodeGeneratorX86::GenerateFrameExit() { | 
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 871 |   __ cfi().RememberState(); | 
 | 872 |   if (!HasEmptyFrame()) { | 
 | 873 |     int adjust = GetFrameSize() - FrameEntrySpillSize(); | 
 | 874 |     __ addl(ESP, Immediate(adjust)); | 
 | 875 |     __ cfi().AdjustCFAOffset(-adjust); | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 876 |  | 
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 877 |     for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { | 
 | 878 |       Register reg = kCoreCalleeSaves[i]; | 
 | 879 |       if (allocated_registers_.ContainsCoreRegister(reg)) { | 
 | 880 |         __ popl(reg); | 
 | 881 |         __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); | 
 | 882 |         __ cfi().Restore(DWARFReg(reg)); | 
 | 883 |       } | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 884 |     } | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 885 |   } | 
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 886 |   __ ret(); | 
 | 887 |   __ cfi().RestoreState(); | 
 | 888 |   __ cfi().DefCFAOffset(GetFrameSize()); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 889 | } | 
 | 890 |  | 
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 891 | void CodeGeneratorX86::Bind(HBasicBlock* block) { | 
 | 892 |   __ Bind(GetLabelOf(block)); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 893 | } | 
 | 894 |  | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 895 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { | 
 | 896 |   switch (load->GetType()) { | 
 | 897 |     case Primitive::kPrimLong: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 898 |     case Primitive::kPrimDouble: | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 899 |       return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 900 |  | 
 | 901 |     case Primitive::kPrimInt: | 
 | 902 |     case Primitive::kPrimNot: | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 903 |     case Primitive::kPrimFloat: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 904 |       return Location::StackSlot(GetStackSlot(load->GetLocal())); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 905 |  | 
 | 906 |     case Primitive::kPrimBoolean: | 
 | 907 |     case Primitive::kPrimByte: | 
 | 908 |     case Primitive::kPrimChar: | 
 | 909 |     case Primitive::kPrimShort: | 
 | 910 |     case Primitive::kPrimVoid: | 
 | 911 |       LOG(FATAL) << "Unexpected type " << load->GetType(); | 
| Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 912 |       UNREACHABLE(); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 913 |   } | 
 | 914 |  | 
 | 915 |   LOG(FATAL) << "Unreachable"; | 
| Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 916 |   UNREACHABLE(); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 917 | } | 
 | 918 |  | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 919 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { | 
 | 920 |   switch (type) { | 
 | 921 |     case Primitive::kPrimBoolean: | 
 | 922 |     case Primitive::kPrimByte: | 
 | 923 |     case Primitive::kPrimChar: | 
 | 924 |     case Primitive::kPrimShort: | 
 | 925 |     case Primitive::kPrimInt: | 
 | 926 |     case Primitive::kPrimNot: | 
 | 927 |       return Location::RegisterLocation(EAX); | 
 | 928 |  | 
 | 929 |     case Primitive::kPrimLong: | 
 | 930 |       return Location::RegisterPairLocation(EAX, EDX); | 
 | 931 |  | 
 | 932 |     case Primitive::kPrimVoid: | 
 | 933 |       return Location::NoLocation(); | 
 | 934 |  | 
 | 935 |     case Primitive::kPrimDouble: | 
 | 936 |     case Primitive::kPrimFloat: | 
 | 937 |       return Location::FpuRegisterLocation(XMM0); | 
 | 938 |   } | 
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 939 |  | 
 | 940 |   UNREACHABLE(); | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 941 | } | 
 | 942 |  | 
 | 943 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { | 
 | 944 |   return Location::RegisterLocation(kMethodRegisterArgument); | 
 | 945 | } | 
 | 946 |  | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 947 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 948 |   switch (type) { | 
 | 949 |     case Primitive::kPrimBoolean: | 
 | 950 |     case Primitive::kPrimByte: | 
 | 951 |     case Primitive::kPrimChar: | 
 | 952 |     case Primitive::kPrimShort: | 
 | 953 |     case Primitive::kPrimInt: | 
 | 954 |     case Primitive::kPrimNot: { | 
 | 955 |       uint32_t index = gp_index_++; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 956 |       stack_index_++; | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 957 |       if (index < calling_convention.GetNumberOfRegisters()) { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 958 |         return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 959 |       } else { | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 960 |         return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); | 
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 961 |       } | 
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 962 |     } | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 963 |  | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 964 |     case Primitive::kPrimLong: { | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 965 |       uint32_t index = gp_index_; | 
 | 966 |       gp_index_ += 2; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 967 |       stack_index_ += 2; | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 968 |       if (index + 1 < calling_convention.GetNumberOfRegisters()) { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 969 |         X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( | 
 | 970 |             calling_convention.GetRegisterPairAt(index)); | 
 | 971 |         return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 972 |       } else { | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 973 |         return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); | 
 | 974 |       } | 
 | 975 |     } | 
 | 976 |  | 
 | 977 |     case Primitive::kPrimFloat: { | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 978 |       uint32_t index = float_index_++; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 979 |       stack_index_++; | 
 | 980 |       if (index < calling_convention.GetNumberOfFpuRegisters()) { | 
 | 981 |         return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); | 
 | 982 |       } else { | 
 | 983 |         return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); | 
 | 984 |       } | 
 | 985 |     } | 
 | 986 |  | 
 | 987 |     case Primitive::kPrimDouble: { | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 988 |       uint32_t index = float_index_++; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 989 |       stack_index_ += 2; | 
 | 990 |       if (index < calling_convention.GetNumberOfFpuRegisters()) { | 
 | 991 |         return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); | 
 | 992 |       } else { | 
 | 993 |         return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 994 |       } | 
 | 995 |     } | 
 | 996 |  | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 997 |     case Primitive::kPrimVoid: | 
 | 998 |       LOG(FATAL) << "Unexpected parameter type " << type; | 
 | 999 |       break; | 
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1000 |   } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1001 |   return Location::NoLocation(); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1002 | } | 
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1003 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1004 | void CodeGeneratorX86::Move32(Location destination, Location source) { | 
 | 1005 |   if (source.Equals(destination)) { | 
 | 1006 |     return; | 
 | 1007 |   } | 
 | 1008 |   if (destination.IsRegister()) { | 
 | 1009 |     if (source.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1010 |       __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1011 |     } else if (source.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1012 |       __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1013 |     } else { | 
 | 1014 |       DCHECK(source.IsStackSlot()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1015 |       __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1016 |     } | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1017 |   } else if (destination.IsFpuRegister()) { | 
 | 1018 |     if (source.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1019 |       __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1020 |     } else if (source.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1021 |       __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1022 |     } else { | 
 | 1023 |       DCHECK(source.IsStackSlot()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1024 |       __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1025 |     } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1026 |   } else { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1027 |     DCHECK(destination.IsStackSlot()) << destination; | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1028 |     if (source.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1029 |       __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1030 |     } else if (source.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1031 |       __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1032 |     } else if (source.IsConstant()) { | 
 | 1033 |       HConstant* constant = source.GetConstant(); | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1034 |       int32_t value = GetInt32ValueOf(constant); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1035 |       __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1036 |     } else { | 
 | 1037 |       DCHECK(source.IsStackSlot()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1038 |       __ pushl(Address(ESP, source.GetStackIndex())); | 
 | 1039 |       __ popl(Address(ESP, destination.GetStackIndex())); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1040 |     } | 
 | 1041 |   } | 
 | 1042 | } | 
 | 1043 |  | 
 | 1044 | void CodeGeneratorX86::Move64(Location destination, Location source) { | 
 | 1045 |   if (source.Equals(destination)) { | 
 | 1046 |     return; | 
 | 1047 |   } | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1048 |   if (destination.IsRegisterPair()) { | 
 | 1049 |     if (source.IsRegisterPair()) { | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1050 |       EmitParallelMoves( | 
 | 1051 |           Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), | 
 | 1052 |           Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1053 |           Primitive::kPrimInt, | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1054 |           Location::RegisterLocation(source.AsRegisterPairLow<Register>()), | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1055 |           Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), | 
 | 1056 |           Primitive::kPrimInt); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1057 |     } else if (source.IsFpuRegister()) { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1058 |       XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); | 
 | 1059 |       __ movd(destination.AsRegisterPairLow<Register>(), src_reg); | 
 | 1060 |       __ psrlq(src_reg, Immediate(32)); | 
 | 1061 |       __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1062 |     } else { | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1063 |       // No conflict possible, so just do the moves. | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1064 |       DCHECK(source.IsDoubleStackSlot()); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1065 |       __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); | 
 | 1066 |       __ movl(destination.AsRegisterPairHigh<Register>(), | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1067 |               Address(ESP, source.GetHighStackIndex(kX86WordSize))); | 
 | 1068 |     } | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1069 |   } else if (destination.IsFpuRegister()) { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1070 |     if (source.IsFpuRegister()) { | 
 | 1071 |       __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
 | 1072 |     } else if (source.IsDoubleStackSlot()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1073 |       __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1074 |     } else if (source.IsRegisterPair()) { | 
 | 1075 |       size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); | 
 | 1076 |       // Create stack space for 2 elements. | 
 | 1077 |       __ subl(ESP, Immediate(2 * elem_size)); | 
 | 1078 |       __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); | 
 | 1079 |       __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); | 
 | 1080 |       __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); | 
 | 1081 |       // And remove the temporary stack space we allocated. | 
 | 1082 |       __ addl(ESP, Immediate(2 * elem_size)); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1083 |     } else { | 
 | 1084 |       LOG(FATAL) << "Unimplemented"; | 
 | 1085 |     } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1086 |   } else { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1087 |     DCHECK(destination.IsDoubleStackSlot()) << destination; | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1088 |     if (source.IsRegisterPair()) { | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1089 |       // No conflict possible, so just do the moves. | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1090 |       __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1091 |       __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1092 |               source.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1093 |     } else if (source.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1094 |       __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1095 |     } else if (source.IsConstant()) { | 
 | 1096 |       HConstant* constant = source.GetConstant(); | 
 | 1097 |       int64_t value; | 
 | 1098 |       if (constant->IsLongConstant()) { | 
 | 1099 |         value = constant->AsLongConstant()->GetValue(); | 
 | 1100 |       } else { | 
 | 1101 |         DCHECK(constant->IsDoubleConstant()); | 
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1102 |         value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1103 |       } | 
 | 1104 |       __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); | 
 | 1105 |       __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1106 |     } else { | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1107 |       DCHECK(source.IsDoubleStackSlot()) << source; | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1108 |       EmitParallelMoves( | 
 | 1109 |           Location::StackSlot(source.GetStackIndex()), | 
 | 1110 |           Location::StackSlot(destination.GetStackIndex()), | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1111 |           Primitive::kPrimInt, | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1112 |           Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1113 |           Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), | 
 | 1114 |           Primitive::kPrimInt); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1115 |     } | 
 | 1116 |   } | 
 | 1117 | } | 
 | 1118 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1119 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { | 
 | 1120 |   DCHECK(location.IsRegister()); | 
 | 1121 |   __ movl(location.AsRegister<Register>(), Immediate(value)); | 
 | 1122 | } | 
 | 1123 |  | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1124 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1125 |   HParallelMove move(GetGraph()->GetArena()); | 
 | 1126 |   if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { | 
 | 1127 |     move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); | 
 | 1128 |     move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1129 |   } else { | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1130 |     move.AddMove(src, dst, dst_type, nullptr); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1131 |   } | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1132 |   GetMoveResolver()->EmitNativeCode(&move); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1133 | } | 
 | 1134 |  | 
 | 1135 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { | 
 | 1136 |   if (location.IsRegister()) { | 
 | 1137 |     locations->AddTemp(location); | 
 | 1138 |   } else if (location.IsRegisterPair()) { | 
 | 1139 |     locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); | 
 | 1140 |     locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); | 
 | 1141 |   } else { | 
 | 1142 |     UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; | 
 | 1143 |   } | 
 | 1144 | } | 
 | 1145 |  | 
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1146 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1147 |   DCHECK(!successor->IsExitBlock()); | 
 | 1148 |  | 
 | 1149 |   HBasicBlock* block = got->GetBlock(); | 
 | 1150 |   HInstruction* previous = got->GetPrevious(); | 
 | 1151 |  | 
 | 1152 |   HLoopInformation* info = block->GetLoopInformation(); | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1153 |   if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1154 |     GenerateSuspendCheck(info->GetSuspendCheck(), successor); | 
 | 1155 |     return; | 
 | 1156 |   } | 
 | 1157 |  | 
 | 1158 |   if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { | 
 | 1159 |     GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); | 
 | 1160 |   } | 
 | 1161 |   if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1162 |     __ jmp(codegen_->GetLabelOf(successor)); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1163 |   } | 
 | 1164 | } | 
 | 1165 |  | 
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1166 | void LocationsBuilderX86::VisitGoto(HGoto* got) { | 
 | 1167 |   got->SetLocations(nullptr); | 
 | 1168 | } | 
 | 1169 |  | 
 | 1170 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { | 
 | 1171 |   HandleGoto(got, got->GetSuccessor()); | 
 | 1172 | } | 
 | 1173 |  | 
 | 1174 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { | 
 | 1175 |   try_boundary->SetLocations(nullptr); | 
 | 1176 | } | 
 | 1177 |  | 
 | 1178 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { | 
 | 1179 |   HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); | 
 | 1180 |   if (!successor->IsExitBlock()) { | 
 | 1181 |     HandleGoto(try_boundary, successor); | 
 | 1182 |   } | 
 | 1183 | } | 
 | 1184 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1185 | void LocationsBuilderX86::VisitExit(HExit* exit) { | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1186 |   exit->SetLocations(nullptr); | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1187 | } | 
 | 1188 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1189 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1190 | } | 
 | 1191 |  | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1192 | template<class LabelType> | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1193 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1194 |                                                   LabelType* true_label, | 
 | 1195 |                                                   LabelType* false_label) { | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1196 |   if (cond->IsFPConditionTrueIfNaN()) { | 
 | 1197 |     __ j(kUnordered, true_label); | 
 | 1198 |   } else if (cond->IsFPConditionFalseIfNaN()) { | 
 | 1199 |     __ j(kUnordered, false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1200 |   } | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1201 |   __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1202 | } | 
 | 1203 |  | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1204 | template<class LabelType> | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1205 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1206 |                                                                LabelType* true_label, | 
 | 1207 |                                                                LabelType* false_label) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1208 |   LocationSummary* locations = cond->GetLocations(); | 
 | 1209 |   Location left = locations->InAt(0); | 
 | 1210 |   Location right = locations->InAt(1); | 
 | 1211 |   IfCondition if_cond = cond->GetCondition(); | 
 | 1212 |  | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1213 |   Register left_high = left.AsRegisterPairHigh<Register>(); | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1214 |   Register left_low = left.AsRegisterPairLow<Register>(); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1215 |   IfCondition true_high_cond = if_cond; | 
 | 1216 |   IfCondition false_high_cond = cond->GetOppositeCondition(); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1217 |   Condition final_condition = X86UnsignedOrFPCondition(if_cond);  // unsigned on lower part | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1218 |  | 
 | 1219 |   // Set the conditions for the test, remembering that == needs to be | 
 | 1220 |   // decided using the low words. | 
 | 1221 |   switch (if_cond) { | 
 | 1222 |     case kCondEQ: | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1223 |     case kCondNE: | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1224 |       // Nothing to do. | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1225 |       break; | 
 | 1226 |     case kCondLT: | 
 | 1227 |       false_high_cond = kCondGT; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1228 |       break; | 
 | 1229 |     case kCondLE: | 
 | 1230 |       true_high_cond = kCondLT; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1231 |       break; | 
 | 1232 |     case kCondGT: | 
 | 1233 |       false_high_cond = kCondLT; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1234 |       break; | 
 | 1235 |     case kCondGE: | 
 | 1236 |       true_high_cond = kCondGT; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1237 |       break; | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1238 |     case kCondB: | 
 | 1239 |       false_high_cond = kCondA; | 
 | 1240 |       break; | 
 | 1241 |     case kCondBE: | 
 | 1242 |       true_high_cond = kCondB; | 
 | 1243 |       break; | 
 | 1244 |     case kCondA: | 
 | 1245 |       false_high_cond = kCondB; | 
 | 1246 |       break; | 
 | 1247 |     case kCondAE: | 
 | 1248 |       true_high_cond = kCondA; | 
 | 1249 |       break; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1250 |   } | 
 | 1251 |  | 
 | 1252 |   if (right.IsConstant()) { | 
 | 1253 |     int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1254 |     int32_t val_high = High32Bits(value); | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1255 |     int32_t val_low = Low32Bits(value); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1256 |  | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1257 |     codegen_->Compare32BitValue(left_high, val_high); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1258 |     if (if_cond == kCondNE) { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1259 |       __ j(X86Condition(true_high_cond), true_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1260 |     } else if (if_cond == kCondEQ) { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1261 |       __ j(X86Condition(false_high_cond), false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1262 |     } else { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1263 |       __ j(X86Condition(true_high_cond), true_label); | 
 | 1264 |       __ j(X86Condition(false_high_cond), false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1265 |     } | 
 | 1266 |     // Must be equal high, so compare the lows. | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1267 |     codegen_->Compare32BitValue(left_low, val_low); | 
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1268 |   } else if (right.IsRegisterPair()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1269 |     Register right_high = right.AsRegisterPairHigh<Register>(); | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1270 |     Register right_low = right.AsRegisterPairLow<Register>(); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1271 |  | 
 | 1272 |     __ cmpl(left_high, right_high); | 
 | 1273 |     if (if_cond == kCondNE) { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1274 |       __ j(X86Condition(true_high_cond), true_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 |     } else if (if_cond == kCondEQ) { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1276 |       __ j(X86Condition(false_high_cond), false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1277 |     } else { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1278 |       __ j(X86Condition(true_high_cond), true_label); | 
 | 1279 |       __ j(X86Condition(false_high_cond), false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1280 |     } | 
 | 1281 |     // Must be equal high, so compare the lows. | 
 | 1282 |     __ cmpl(left_low, right_low); | 
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1283 |   } else { | 
 | 1284 |     DCHECK(right.IsDoubleStackSlot()); | 
 | 1285 |     __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); | 
 | 1286 |     if (if_cond == kCondNE) { | 
 | 1287 |       __ j(X86Condition(true_high_cond), true_label); | 
 | 1288 |     } else if (if_cond == kCondEQ) { | 
 | 1289 |       __ j(X86Condition(false_high_cond), false_label); | 
 | 1290 |     } else { | 
 | 1291 |       __ j(X86Condition(true_high_cond), true_label); | 
 | 1292 |       __ j(X86Condition(false_high_cond), false_label); | 
 | 1293 |     } | 
 | 1294 |     // Must be equal high, so compare the lows. | 
 | 1295 |     __ cmpl(left_low, Address(ESP, right.GetStackIndex())); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1296 |   } | 
 | 1297 |   // The last comparison might be unsigned. | 
 | 1298 |   __ j(final_condition, true_label); | 
 | 1299 | } | 
 | 1300 |  | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1301 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, | 
 | 1302 |                                                     Location rhs, | 
 | 1303 |                                                     HInstruction* insn, | 
 | 1304 |                                                     bool is_double) { | 
 | 1305 |   HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); | 
 | 1306 |   if (is_double) { | 
 | 1307 |     if (rhs.IsFpuRegister()) { | 
 | 1308 |       __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); | 
 | 1309 |     } else if (const_area != nullptr) { | 
 | 1310 |       DCHECK(const_area->IsEmittedAtUseSite()); | 
 | 1311 |       __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), | 
 | 1312 |                  codegen_->LiteralDoubleAddress( | 
 | 1313 |                    const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
 | 1314 |                    const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 1315 |     } else { | 
 | 1316 |       DCHECK(rhs.IsDoubleStackSlot()); | 
 | 1317 |       __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); | 
 | 1318 |     } | 
 | 1319 |   } else { | 
 | 1320 |     if (rhs.IsFpuRegister()) { | 
 | 1321 |       __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); | 
 | 1322 |     } else if (const_area != nullptr) { | 
 | 1323 |       DCHECK(const_area->IsEmittedAtUseSite()); | 
 | 1324 |       __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), | 
 | 1325 |                  codegen_->LiteralFloatAddress( | 
 | 1326 |                    const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
 | 1327 |                    const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 1328 |     } else { | 
 | 1329 |       DCHECK(rhs.IsStackSlot()); | 
 | 1330 |       __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); | 
 | 1331 |     } | 
 | 1332 |   } | 
 | 1333 | } | 
 | 1334 |  | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1335 | template<class LabelType> | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1336 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1337 |                                                                LabelType* true_target_in, | 
 | 1338 |                                                                LabelType* false_target_in) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1339 |   // Generated branching requires both targets to be explicit. If either of the | 
 | 1340 |   // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1341 |   LabelType fallthrough_target; | 
 | 1342 |   LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; | 
 | 1343 |   LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1344 |  | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1345 |   LocationSummary* locations = condition->GetLocations(); | 
 | 1346 |   Location left = locations->InAt(0); | 
 | 1347 |   Location right = locations->InAt(1); | 
 | 1348 |  | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1349 |   Primitive::Type type = condition->InputAt(0)->GetType(); | 
 | 1350 |   switch (type) { | 
 | 1351 |     case Primitive::kPrimLong: | 
 | 1352 |       GenerateLongComparesAndJumps(condition, true_target, false_target); | 
 | 1353 |       break; | 
 | 1354 |     case Primitive::kPrimFloat: | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1355 |       GenerateFPCompare(left, right, condition, false); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1356 |       GenerateFPJumps(condition, true_target, false_target); | 
 | 1357 |       break; | 
 | 1358 |     case Primitive::kPrimDouble: | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1359 |       GenerateFPCompare(left, right, condition, true); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1360 |       GenerateFPJumps(condition, true_target, false_target); | 
 | 1361 |       break; | 
 | 1362 |     default: | 
 | 1363 |       LOG(FATAL) << "Unexpected compare type " << type; | 
 | 1364 |   } | 
 | 1365 |  | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1366 |   if (false_target != &fallthrough_target) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1367 |     __ jmp(false_target); | 
 | 1368 |   } | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1369 |  | 
 | 1370 |   if (fallthrough_target.IsLinked()) { | 
 | 1371 |     __ Bind(&fallthrough_target); | 
 | 1372 |   } | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1373 | } | 
 | 1374 |  | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1375 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { | 
 | 1376 |   // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS | 
 | 1377 |   // are set only strictly before `branch`. We can't use the eflags on long/FP | 
 | 1378 |   // conditions if they are materialized due to the complex branching. | 
 | 1379 |   return cond->IsCondition() && | 
 | 1380 |          cond->GetNext() == branch && | 
 | 1381 |          cond->InputAt(0)->GetType() != Primitive::kPrimLong && | 
 | 1382 |          !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); | 
 | 1383 | } | 
 | 1384 |  | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1385 | template<class LabelType> | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1386 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1387 |                                                         size_t condition_input_index, | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1388 |                                                         LabelType* true_target, | 
 | 1389 |                                                         LabelType* false_target) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1390 |   HInstruction* cond = instruction->InputAt(condition_input_index); | 
 | 1391 |  | 
 | 1392 |   if (true_target == nullptr && false_target == nullptr) { | 
 | 1393 |     // Nothing to do. The code always falls through. | 
 | 1394 |     return; | 
 | 1395 |   } else if (cond->IsIntConstant()) { | 
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1396 |     // Constant condition, statically compared against "true" (integer value 1). | 
 | 1397 |     if (cond->AsIntConstant()->IsTrue()) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1398 |       if (true_target != nullptr) { | 
 | 1399 |         __ jmp(true_target); | 
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1400 |       } | 
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1401 |     } else { | 
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1402 |       DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1403 |       if (false_target != nullptr) { | 
 | 1404 |         __ jmp(false_target); | 
 | 1405 |       } | 
 | 1406 |     } | 
 | 1407 |     return; | 
 | 1408 |   } | 
 | 1409 |  | 
 | 1410 |   // The following code generates these patterns: | 
 | 1411 |   //  (1) true_target == nullptr && false_target != nullptr | 
 | 1412 |   //        - opposite condition true => branch to false_target | 
 | 1413 |   //  (2) true_target != nullptr && false_target == nullptr | 
 | 1414 |   //        - condition true => branch to true_target | 
 | 1415 |   //  (3) true_target != nullptr && false_target != nullptr | 
 | 1416 |   //        - condition true => branch to true_target | 
 | 1417 |   //        - branch to false_target | 
 | 1418 |   if (IsBooleanValueOrMaterializedCondition(cond)) { | 
 | 1419 |     if (AreEflagsSetFrom(cond, instruction)) { | 
 | 1420 |       if (true_target == nullptr) { | 
 | 1421 |         __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); | 
 | 1422 |       } else { | 
 | 1423 |         __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); | 
 | 1424 |       } | 
 | 1425 |     } else { | 
 | 1426 |       // Materialized condition, compare against 0. | 
 | 1427 |       Location lhs = instruction->GetLocations()->InAt(condition_input_index); | 
 | 1428 |       if (lhs.IsRegister()) { | 
 | 1429 |         __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); | 
 | 1430 |       } else { | 
 | 1431 |         __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); | 
 | 1432 |       } | 
 | 1433 |       if (true_target == nullptr) { | 
 | 1434 |         __ j(kEqual, false_target); | 
 | 1435 |       } else { | 
 | 1436 |         __ j(kNotEqual, true_target); | 
 | 1437 |       } | 
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1438 |     } | 
 | 1439 |   } else { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1440 |     // Condition has not been materialized, use its inputs as the comparison and | 
 | 1441 |     // its condition as the branch condition. | 
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1442 |     HCondition* condition = cond->AsCondition(); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1443 |  | 
 | 1444 |     // If this is a long or FP comparison that has been folded into | 
 | 1445 |     // the HCondition, generate the comparison directly. | 
 | 1446 |     Primitive::Type type = condition->InputAt(0)->GetType(); | 
 | 1447 |     if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { | 
 | 1448 |       GenerateCompareTestAndBranch(condition, true_target, false_target); | 
 | 1449 |       return; | 
 | 1450 |     } | 
 | 1451 |  | 
 | 1452 |     Location lhs = condition->GetLocations()->InAt(0); | 
 | 1453 |     Location rhs = condition->GetLocations()->InAt(1); | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1454 |     // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1455 |     if (rhs.IsRegister()) { | 
 | 1456 |       __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); | 
 | 1457 |     } else if (rhs.IsConstant()) { | 
 | 1458 |       int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1459 |       codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); | 
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1460 |     } else { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1461 |       __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); | 
 | 1462 |     } | 
 | 1463 |     if (true_target == nullptr) { | 
 | 1464 |       __ j(X86Condition(condition->GetOppositeCondition()), false_target); | 
 | 1465 |     } else { | 
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1466 |       __ j(X86Condition(condition->GetCondition()), true_target); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1467 |     } | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1468 |   } | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1469 |  | 
 | 1470 |   // If neither branch falls through (case 3), the conditional branch to `true_target` | 
 | 1471 |   // was already emitted (case 2) and we need to emit a jump to `false_target`. | 
 | 1472 |   if (true_target != nullptr && false_target != nullptr) { | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1473 |     __ jmp(false_target); | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1474 |   } | 
 | 1475 | } | 
 | 1476 |  | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1477 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1478 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); | 
 | 1479 |   if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1480 |     locations->SetInAt(0, Location::Any()); | 
 | 1481 |   } | 
 | 1482 | } | 
 | 1483 |  | 
 | 1484 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1485 |   HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); | 
 | 1486 |   HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); | 
 | 1487 |   Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? | 
 | 1488 |       nullptr : codegen_->GetLabelOf(true_successor); | 
 | 1489 |   Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? | 
 | 1490 |       nullptr : codegen_->GetLabelOf(false_successor); | 
 | 1491 |   GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1492 | } | 
 | 1493 |  | 
 | 1494 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { | 
 | 1495 |   LocationSummary* locations = new (GetGraph()->GetArena()) | 
 | 1496 |       LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1497 |   if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1498 |     locations->SetInAt(0, Location::Any()); | 
 | 1499 |   } | 
 | 1500 | } | 
 | 1501 |  | 
 | 1502 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1503 |   SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1504 |   GenerateTestAndBranch<Label>(deoptimize, | 
 | 1505 |                                /* condition_input_index */ 0, | 
 | 1506 |                                slow_path->GetEntryLabel(), | 
 | 1507 |                                /* false_target */ nullptr); | 
 | 1508 | } | 
 | 1509 |  | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1510 | static bool SelectCanUseCMOV(HSelect* select) { | 
 | 1511 |   // There are no conditional move instructions for XMMs. | 
 | 1512 |   if (Primitive::IsFloatingPointType(select->GetType())) { | 
 | 1513 |     return false; | 
 | 1514 |   } | 
 | 1515 |  | 
 | 1516 |   // A FP condition doesn't generate the single CC that we need. | 
 | 1517 |   // In 32 bit mode, a long condition doesn't generate a single CC either. | 
 | 1518 |   HInstruction* condition = select->GetCondition(); | 
 | 1519 |   if (condition->IsCondition()) { | 
 | 1520 |     Primitive::Type compare_type = condition->InputAt(0)->GetType(); | 
 | 1521 |     if (compare_type == Primitive::kPrimLong || | 
 | 1522 |         Primitive::IsFloatingPointType(compare_type)) { | 
 | 1523 |       return false; | 
 | 1524 |     } | 
 | 1525 |   } | 
 | 1526 |  | 
 | 1527 |   // We can generate a CMOV for this Select. | 
 | 1528 |   return true; | 
 | 1529 | } | 
 | 1530 |  | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1531 | void LocationsBuilderX86::VisitSelect(HSelect* select) { | 
 | 1532 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1533 |   if (Primitive::IsFloatingPointType(select->GetType())) { | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1534 |     locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1535 |     locations->SetInAt(1, Location::Any()); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1536 |   } else { | 
 | 1537 |     locations->SetInAt(0, Location::RequiresRegister()); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1538 |     if (SelectCanUseCMOV(select)) { | 
 | 1539 |       if (select->InputAt(1)->IsConstant()) { | 
 | 1540 |         // Cmov can't handle a constant value. | 
 | 1541 |         locations->SetInAt(1, Location::RequiresRegister()); | 
 | 1542 |       } else { | 
 | 1543 |         locations->SetInAt(1, Location::Any()); | 
 | 1544 |       } | 
 | 1545 |     } else { | 
 | 1546 |       locations->SetInAt(1, Location::Any()); | 
 | 1547 |     } | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1548 |   } | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1549 |   if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { | 
 | 1550 |     locations->SetInAt(2, Location::RequiresRegister()); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1551 |   } | 
 | 1552 |   locations->SetOut(Location::SameAsFirstInput()); | 
 | 1553 | } | 
 | 1554 |  | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1555 | void InstructionCodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { | 
 | 1556 |   Register lhs_reg = lhs.AsRegister<Register>(); | 
 | 1557 |   if (rhs.IsConstant()) { | 
 | 1558 |     int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); | 
 | 1559 |     codegen_->Compare32BitValue(lhs_reg, value); | 
 | 1560 |   } else if (rhs.IsStackSlot()) { | 
 | 1561 |     __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); | 
 | 1562 |   } else { | 
 | 1563 |     __ cmpl(lhs_reg, rhs.AsRegister<Register>()); | 
 | 1564 |   } | 
 | 1565 | } | 
 | 1566 |  | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1567 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { | 
 | 1568 |   LocationSummary* locations = select->GetLocations(); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1569 |   DCHECK(locations->InAt(0).Equals(locations->Out())); | 
 | 1570 |   if (SelectCanUseCMOV(select)) { | 
 | 1571 |     // If both the condition and the source types are integer, we can generate | 
 | 1572 |     // a CMOV to implement Select. | 
 | 1573 |  | 
 | 1574 |     HInstruction* select_condition = select->GetCondition(); | 
 | 1575 |     Condition cond = kNotEqual; | 
 | 1576 |  | 
 | 1577 |     // Figure out how to test the 'condition'. | 
 | 1578 |     if (select_condition->IsCondition()) { | 
 | 1579 |       HCondition* condition = select_condition->AsCondition(); | 
 | 1580 |       if (!condition->IsEmittedAtUseSite()) { | 
 | 1581 |         // This was a previously materialized condition. | 
 | 1582 |         // Can we use the existing condition code? | 
 | 1583 |         if (AreEflagsSetFrom(condition, select)) { | 
 | 1584 |           // Materialization was the previous instruction. Condition codes are right. | 
 | 1585 |           cond = X86Condition(condition->GetCondition()); | 
 | 1586 |         } else { | 
 | 1587 |           // No, we have to recreate the condition code. | 
 | 1588 |           Register cond_reg = locations->InAt(2).AsRegister<Register>(); | 
 | 1589 |           __ testl(cond_reg, cond_reg); | 
 | 1590 |         } | 
 | 1591 |       } else { | 
 | 1592 |         // We can't handle FP or long here. | 
 | 1593 |         DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); | 
 | 1594 |         DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); | 
 | 1595 |         LocationSummary* cond_locations = condition->GetLocations(); | 
 | 1596 |         GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); | 
 | 1597 |         cond = X86Condition(condition->GetCondition()); | 
 | 1598 |       } | 
 | 1599 |     } else { | 
 | 1600 |       // Must be a boolean condition, which needs to be compared to 0. | 
 | 1601 |       Register cond_reg = locations->InAt(2).AsRegister<Register>(); | 
 | 1602 |       __ testl(cond_reg, cond_reg); | 
 | 1603 |     } | 
 | 1604 |  | 
 | 1605 |     // If the condition is true, overwrite the output, which already contains false. | 
 | 1606 |     Location false_loc = locations->InAt(0); | 
 | 1607 |     Location true_loc = locations->InAt(1); | 
 | 1608 |     if (select->GetType() == Primitive::kPrimLong) { | 
 | 1609 |       // 64 bit conditional move. | 
 | 1610 |       Register false_high = false_loc.AsRegisterPairHigh<Register>(); | 
 | 1611 |       Register false_low = false_loc.AsRegisterPairLow<Register>(); | 
 | 1612 |       if (true_loc.IsRegisterPair()) { | 
 | 1613 |         __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); | 
 | 1614 |         __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); | 
 | 1615 |       } else { | 
 | 1616 |         __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); | 
 | 1617 |         __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); | 
 | 1618 |       } | 
 | 1619 |     } else { | 
 | 1620 |       // 32 bit conditional move. | 
 | 1621 |       Register false_reg = false_loc.AsRegister<Register>(); | 
 | 1622 |       if (true_loc.IsRegister()) { | 
 | 1623 |         __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); | 
 | 1624 |       } else { | 
 | 1625 |         __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); | 
 | 1626 |       } | 
 | 1627 |     } | 
 | 1628 |   } else { | 
 | 1629 |     NearLabel false_target; | 
 | 1630 |     GenerateTestAndBranch<NearLabel>( | 
 | 1631 |         select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); | 
 | 1632 |     codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); | 
 | 1633 |     __ Bind(&false_target); | 
 | 1634 |   } | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1635 | } | 
 | 1636 |  | 
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1637 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { | 
 | 1638 |   new (GetGraph()->GetArena()) LocationSummary(info); | 
 | 1639 | } | 
 | 1640 |  | 
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1641 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { | 
 | 1642 |   // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. | 
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1643 | } | 
 | 1644 |  | 
 | 1645 | void CodeGeneratorX86::GenerateNop() { | 
 | 1646 |   __ nop(); | 
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1647 | } | 
 | 1648 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1649 | void LocationsBuilderX86::VisitLocal(HLocal* local) { | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1650 |   local->SetLocations(nullptr); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1651 | } | 
 | 1652 |  | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1653 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { | 
 | 1654 |   DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); | 
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1655 | } | 
 | 1656 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1657 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { | 
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1658 |   local->SetLocations(nullptr); | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1659 | } | 
 | 1660 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1661 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1662 |   // Nothing to do, this is driven by the code generator. | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1663 | } | 
 | 1664 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1665 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1666 |   LocationSummary* locations = | 
 | 1667 |       new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1668 |   switch (store->InputAt(1)->GetType()) { | 
 | 1669 |     case Primitive::kPrimBoolean: | 
 | 1670 |     case Primitive::kPrimByte: | 
 | 1671 |     case Primitive::kPrimChar: | 
 | 1672 |     case Primitive::kPrimShort: | 
 | 1673 |     case Primitive::kPrimInt: | 
 | 1674 |     case Primitive::kPrimNot: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1675 |     case Primitive::kPrimFloat: | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1676 |       locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); | 
 | 1677 |       break; | 
 | 1678 |  | 
 | 1679 |     case Primitive::kPrimLong: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1680 |     case Primitive::kPrimDouble: | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1681 |       locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); | 
 | 1682 |       break; | 
 | 1683 |  | 
 | 1684 |     default: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1685 |       LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1686 |   } | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1687 | } | 
 | 1688 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1689 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1690 | } | 
 | 1691 |  | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1692 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1693 |   LocationSummary* locations = | 
| Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1694 |       new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1695 |   // Handle the long/FP comparisons made in instruction simplification. | 
 | 1696 |   switch (cond->InputAt(0)->GetType()) { | 
 | 1697 |     case Primitive::kPrimLong: { | 
 | 1698 |       locations->SetInAt(0, Location::RequiresRegister()); | 
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1699 |       locations->SetInAt(1, Location::Any()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1700 |       if (!cond->IsEmittedAtUseSite()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1701 |         locations->SetOut(Location::RequiresRegister()); | 
 | 1702 |       } | 
 | 1703 |       break; | 
 | 1704 |     } | 
 | 1705 |     case Primitive::kPrimFloat: | 
 | 1706 |     case Primitive::kPrimDouble: { | 
 | 1707 |       locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1708 |       if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 1709 |         DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); | 
 | 1710 |       } else if (cond->InputAt(1)->IsConstant()) { | 
 | 1711 |         locations->SetInAt(1, Location::RequiresFpuRegister()); | 
 | 1712 |       } else { | 
 | 1713 |         locations->SetInAt(1, Location::Any()); | 
 | 1714 |       } | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1715 |       if (!cond->IsEmittedAtUseSite()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1716 |         locations->SetOut(Location::RequiresRegister()); | 
 | 1717 |       } | 
 | 1718 |       break; | 
 | 1719 |     } | 
 | 1720 |     default: | 
 | 1721 |       locations->SetInAt(0, Location::RequiresRegister()); | 
 | 1722 |       locations->SetInAt(1, Location::Any()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1723 |       if (!cond->IsEmittedAtUseSite()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1724 |         // We need a byte register. | 
 | 1725 |         locations->SetOut(Location::RegisterLocation(ECX)); | 
 | 1726 |       } | 
 | 1727 |       break; | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1728 |   } | 
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1729 | } | 
 | 1730 |  | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1731 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1732 |   if (cond->IsEmittedAtUseSite()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1733 |     return; | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1734 |   } | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1735 |  | 
 | 1736 |   LocationSummary* locations = cond->GetLocations(); | 
 | 1737 |   Location lhs = locations->InAt(0); | 
 | 1738 |   Location rhs = locations->InAt(1); | 
 | 1739 |   Register reg = locations->Out().AsRegister<Register>(); | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1740 |   NearLabel true_label, false_label; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1741 |  | 
 | 1742 |   switch (cond->InputAt(0)->GetType()) { | 
 | 1743 |     default: { | 
 | 1744 |       // Integer case. | 
 | 1745 |  | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1746 |       // Clear output register: setb only sets the low byte. | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1747 |       __ xorl(reg, reg); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1748 |       GenerateIntCompare(lhs, rhs); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1749 |       __ setb(X86Condition(cond->GetCondition()), reg); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1750 |       return; | 
 | 1751 |     } | 
 | 1752 |     case Primitive::kPrimLong: | 
 | 1753 |       GenerateLongComparesAndJumps(cond, &true_label, &false_label); | 
 | 1754 |       break; | 
 | 1755 |     case Primitive::kPrimFloat: | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1756 |       GenerateFPCompare(lhs, rhs, cond, false); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1757 |       GenerateFPJumps(cond, &true_label, &false_label); | 
 | 1758 |       break; | 
 | 1759 |     case Primitive::kPrimDouble: | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1760 |       GenerateFPCompare(lhs, rhs, cond, true); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1761 |       GenerateFPJumps(cond, &true_label, &false_label); | 
 | 1762 |       break; | 
 | 1763 |   } | 
 | 1764 |  | 
 | 1765 |   // Convert the jumps into the result. | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1766 |   NearLabel done_label; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1767 |  | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1768 |   // False case: result = 0. | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1769 |   __ Bind(&false_label); | 
 | 1770 |   __ xorl(reg, reg); | 
 | 1771 |   __ jmp(&done_label); | 
 | 1772 |  | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1773 |   // True case: result = 1. | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1774 |   __ Bind(&true_label); | 
 | 1775 |   __ movl(reg, Immediate(1)); | 
 | 1776 |   __ Bind(&done_label); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1777 | } | 
 | 1778 |  | 
 | 1779 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1780 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1781 | } | 
 | 1782 |  | 
 | 1783 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1784 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1785 | } | 
 | 1786 |  | 
 | 1787 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1788 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1789 | } | 
 | 1790 |  | 
 | 1791 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1793 | } | 
 | 1794 |  | 
 | 1795 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1796 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1797 | } | 
 | 1798 |  | 
 | 1799 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1800 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1801 | } | 
 | 1802 |  | 
 | 1803 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1804 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1805 | } | 
 | 1806 |  | 
 | 1807 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1808 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1809 | } | 
 | 1810 |  | 
 | 1811 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1812 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1813 | } | 
 | 1814 |  | 
 | 1815 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1816 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1817 | } | 
 | 1818 |  | 
 | 1819 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1820 |   HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1821 | } | 
 | 1822 |  | 
 | 1823 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1824 |   HandleCondition(comp); | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1825 | } | 
 | 1826 |  | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1827 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1828 |   HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1829 | } | 
 | 1830 |  | 
 | 1831 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1832 |   HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1833 | } | 
 | 1834 |  | 
 | 1835 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1836 |   HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1837 | } | 
 | 1838 |  | 
 | 1839 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1840 |   HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1841 | } | 
 | 1842 |  | 
 | 1843 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1844 |   HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1845 | } | 
 | 1846 |  | 
 | 1847 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1848 |   HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1849 | } | 
 | 1850 |  | 
 | 1851 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1852 |   HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1853 | } | 
 | 1854 |  | 
 | 1855 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1856 |   HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1857 | } | 
 | 1858 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1859 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1860 |   LocationSummary* locations = | 
 | 1861 |       new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1862 |   locations->SetOut(Location::ConstantLocation(constant)); | 
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1863 | } | 
 | 1864 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1865 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { | 
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1866 |   // Will be generated at use site. | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1867 | } | 
 | 1868 |  | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1869 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { | 
 | 1870 |   LocationSummary* locations = | 
 | 1871 |       new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
 | 1872 |   locations->SetOut(Location::ConstantLocation(constant)); | 
 | 1873 | } | 
 | 1874 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1875 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1876 |   // Will be generated at use site. | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1877 | } | 
 | 1878 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1879 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1880 |   LocationSummary* locations = | 
 | 1881 |       new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1882 |   locations->SetOut(Location::ConstantLocation(constant)); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1883 | } | 
 | 1884 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1885 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1886 |   // Will be generated at use site. | 
 | 1887 | } | 
 | 1888 |  | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1889 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { | 
 | 1890 |   LocationSummary* locations = | 
 | 1891 |       new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
 | 1892 |   locations->SetOut(Location::ConstantLocation(constant)); | 
 | 1893 | } | 
 | 1894 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1895 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1896 |   // Will be generated at use site. | 
 | 1897 | } | 
 | 1898 |  | 
 | 1899 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { | 
 | 1900 |   LocationSummary* locations = | 
 | 1901 |       new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); | 
 | 1902 |   locations->SetOut(Location::ConstantLocation(constant)); | 
 | 1903 | } | 
 | 1904 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1905 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1906 |   // Will be generated at use site. | 
 | 1907 | } | 
 | 1908 |  | 
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1909 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
 | 1910 |   memory_barrier->SetLocations(nullptr); | 
 | 1911 | } | 
 | 1912 |  | 
 | 1913 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1914 |   codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); | 
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1915 | } | 
 | 1916 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1917 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1918 |   ret->SetLocations(nullptr); | 
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1919 | } | 
 | 1920 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1921 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1922 |   codegen_->GenerateFrameExit(); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1923 | } | 
 | 1924 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1925 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1926 |   LocationSummary* locations = | 
 | 1927 |       new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1928 |   switch (ret->InputAt(0)->GetType()) { | 
 | 1929 |     case Primitive::kPrimBoolean: | 
 | 1930 |     case Primitive::kPrimByte: | 
 | 1931 |     case Primitive::kPrimChar: | 
 | 1932 |     case Primitive::kPrimShort: | 
 | 1933 |     case Primitive::kPrimInt: | 
 | 1934 |     case Primitive::kPrimNot: | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1935 |       locations->SetInAt(0, Location::RegisterLocation(EAX)); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1936 |       break; | 
 | 1937 |  | 
 | 1938 |     case Primitive::kPrimLong: | 
 | 1939 |       locations->SetInAt( | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1940 |           0, Location::RegisterPairLocation(EAX, EDX)); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1941 |       break; | 
 | 1942 |  | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1943 |     case Primitive::kPrimFloat: | 
 | 1944 |     case Primitive::kPrimDouble: | 
 | 1945 |       locations->SetInAt( | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1946 |           0, Location::FpuRegisterLocation(XMM0)); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1947 |       break; | 
 | 1948 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1949 |     default: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1950 |       LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1951 |   } | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1952 | } | 
 | 1953 |  | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1954 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1955 |   if (kIsDebugBuild) { | 
 | 1956 |     switch (ret->InputAt(0)->GetType()) { | 
 | 1957 |       case Primitive::kPrimBoolean: | 
 | 1958 |       case Primitive::kPrimByte: | 
 | 1959 |       case Primitive::kPrimChar: | 
 | 1960 |       case Primitive::kPrimShort: | 
 | 1961 |       case Primitive::kPrimInt: | 
 | 1962 |       case Primitive::kPrimNot: | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1963 |         DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1964 |         break; | 
 | 1965 |  | 
 | 1966 |       case Primitive::kPrimLong: | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1967 |         DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); | 
 | 1968 |         DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1969 |         break; | 
 | 1970 |  | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1971 |       case Primitive::kPrimFloat: | 
 | 1972 |       case Primitive::kPrimDouble: | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1973 |         DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1974 |         break; | 
 | 1975 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1976 |       default: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1977 |         LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1978 |     } | 
 | 1979 |   } | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1980 |   codegen_->GenerateFrameExit(); | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1981 | } | 
 | 1982 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1983 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
 | 1984 |   // The trampoline uses the same calling convention as dex calling conventions, | 
 | 1985 |   // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain | 
 | 1986 |   // the method_idx. | 
 | 1987 |   HandleInvoke(invoke); | 
 | 1988 | } | 
 | 1989 |  | 
 | 1990 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
 | 1991 |   codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); | 
 | 1992 | } | 
 | 1993 |  | 
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1994 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1995 |   // Explicit clinit checks triggered by static invokes must have been pruned by | 
 | 1996 |   // art::PrepareForRegisterAllocation. | 
 | 1997 |   DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); | 
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1998 |  | 
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1999 |   IntrinsicLocationsBuilderX86 intrinsic(codegen_); | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2000 |   if (intrinsic.TryDispatch(invoke)) { | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2001 |     if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2002 |       invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2003 |     } | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2004 |     return; | 
 | 2005 |   } | 
 | 2006 |  | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2007 |   HandleInvoke(invoke); | 
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2008 |  | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2009 |   // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. | 
 | 2010 |   if (invoke->HasPcRelativeDexCache()) { | 
| Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2011 |     invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2012 |   } | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2013 | } | 
 | 2014 |  | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2015 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { | 
 | 2016 |   if (invoke->GetLocations()->Intrinsified()) { | 
 | 2017 |     IntrinsicCodeGeneratorX86 intrinsic(codegen); | 
 | 2018 |     intrinsic.Dispatch(invoke); | 
 | 2019 |     return true; | 
 | 2020 |   } | 
 | 2021 |   return false; | 
 | 2022 | } | 
 | 2023 |  | 
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2024 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2025 |   // Explicit clinit checks triggered by static invokes must have been pruned by | 
 | 2026 |   // art::PrepareForRegisterAllocation. | 
 | 2027 |   DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); | 
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2028 |  | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2029 |   if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
 | 2030 |     return; | 
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2031 |   } | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2032 |  | 
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2033 |   LocationSummary* locations = invoke->GetLocations(); | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2034 |   codegen_->GenerateStaticOrDirectCall( | 
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2035 |       invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); | 
| Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2036 |   codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2037 | } | 
 | 2038 |  | 
 | 2039 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2040 |   IntrinsicLocationsBuilderX86 intrinsic(codegen_); | 
 | 2041 |   if (intrinsic.TryDispatch(invoke)) { | 
 | 2042 |     return; | 
 | 2043 |   } | 
 | 2044 |  | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2045 |   HandleInvoke(invoke); | 
 | 2046 | } | 
 | 2047 |  | 
 | 2048 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2049 |   InvokeDexCallingConventionVisitorX86 calling_convention_visitor; | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2050 |   CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); | 
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2051 | } | 
 | 2052 |  | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2053 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2054 |   if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
 | 2055 |     return; | 
 | 2056 |   } | 
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2057 |  | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2058 |   codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); | 
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2059 |   DCHECK(!codegen_->IsLeafMethod()); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2060 |   codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2061 | } | 
 | 2062 |  | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2063 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2064 |   // This call to HandleInvoke allocates a temporary (core) register | 
 | 2065 |   // which is also used to transfer the hidden argument from FP to | 
 | 2066 |   // core register. | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2067 |   HandleInvoke(invoke); | 
 | 2068 |   // Add the hidden argument. | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2069 |   invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2070 | } | 
 | 2071 |  | 
 | 2072 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { | 
 | 2073 |   // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2074 |   LocationSummary* locations = invoke->GetLocations(); | 
 | 2075 |   Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
 | 2076 |   XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2077 |   uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( | 
 | 2078 |       invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2079 |   Location receiver = locations->InAt(0); | 
 | 2080 |   uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
 | 2081 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2082 |   // Set the hidden argument. This is safe to do this here, as XMM7 | 
 | 2083 |   // won't be modified thereafter, before the `call` instruction. | 
 | 2084 |   DCHECK_EQ(XMM7, hidden_reg); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2085 |   __ movl(temp, Immediate(invoke->GetDexMethodIndex())); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2086 |   __ movd(hidden_reg, temp); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2087 |  | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2088 |   if (receiver.IsStackSlot()) { | 
 | 2089 |     __ movl(temp, Address(ESP, receiver.GetStackIndex())); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2090 |     // /* HeapReference<Class> */ temp = temp->klass_ | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2091 |     __ movl(temp, Address(temp, class_offset)); | 
 | 2092 |   } else { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2093 |     // /* HeapReference<Class> */ temp = receiver->klass_ | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2094 |     __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2095 |   } | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2096 |   codegen_->MaybeRecordImplicitNullCheck(invoke); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2097 |   // Instead of simply (possibly) unpoisoning `temp` here, we should | 
 | 2098 |   // emit a read barrier for the previous class reference load. | 
 | 2099 |   // However this is not required in practice, as this is an | 
 | 2100 |   // intermediate/temporary reference and because the current | 
 | 2101 |   // concurrent copying collector keeps the from-space memory | 
 | 2102 |   // intact/accessible until the end of the marking phase (the | 
 | 2103 |   // concurrent copying collector may not in the future). | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2104 |   __ MaybeUnpoisonHeapReference(temp); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2105 |   // temp = temp->GetImtEntryAt(method_offset); | 
 | 2106 |   __ movl(temp, Address(temp, method_offset)); | 
 | 2107 |   // call temp->GetEntryPoint(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2108 |   __ call(Address(temp, | 
 | 2109 |                   ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2110 |  | 
 | 2111 |   DCHECK(!codegen_->IsLeafMethod()); | 
 | 2112 |   codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
 | 2113 | } | 
 | 2114 |  | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2115 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { | 
 | 2116 |   LocationSummary* locations = | 
 | 2117 |       new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); | 
 | 2118 |   switch (neg->GetResultType()) { | 
 | 2119 |     case Primitive::kPrimInt: | 
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2120 |     case Primitive::kPrimLong: | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2121 |       locations->SetInAt(0, Location::RequiresRegister()); | 
 | 2122 |       locations->SetOut(Location::SameAsFirstInput()); | 
 | 2123 |       break; | 
 | 2124 |  | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2125 |     case Primitive::kPrimFloat: | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2126 |       locations->SetInAt(0, Location::RequiresFpuRegister()); | 
 | 2127 |       locations->SetOut(Location::SameAsFirstInput()); | 
 | 2128 |       locations->AddTemp(Location::RequiresRegister()); | 
 | 2129 |       locations->AddTemp(Location::RequiresFpuRegister()); | 
 | 2130 |       break; | 
 | 2131 |  | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2132 |     case Primitive::kPrimDouble: | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2133 |       locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2134 |       locations->SetOut(Location::SameAsFirstInput()); | 
 | 2135 |       locations->AddTemp(Location::RequiresFpuRegister()); | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2136 |       break; | 
 | 2137 |  | 
 | 2138 |     default: | 
 | 2139 |       LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); | 
 | 2140 |   } | 
 | 2141 | } | 
 | 2142 |  | 
 | 2143 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { | 
 | 2144 |   LocationSummary* locations = neg->GetLocations(); | 
 | 2145 |   Location out = locations->Out(); | 
 | 2146 |   Location in = locations->InAt(0); | 
 | 2147 |   switch (neg->GetResultType()) { | 
 | 2148 |     case Primitive::kPrimInt: | 
 | 2149 |       DCHECK(in.IsRegister()); | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2150 |       DCHECK(in.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2151 |       __ negl(out.AsRegister<Register>()); | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2152 |       break; | 
 | 2153 |  | 
 | 2154 |     case Primitive::kPrimLong: | 
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2155 |       DCHECK(in.IsRegisterPair()); | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2156 |       DCHECK(in.Equals(out)); | 
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2157 |       __ negl(out.AsRegisterPairLow<Register>()); | 
 | 2158 |       // Negation is similar to subtraction from zero.  The least | 
 | 2159 |       // significant byte triggers a borrow when it is different from | 
 | 2160 |       // zero; to take it into account, add 1 to the most significant | 
 | 2161 |       // byte if the carry flag (CF) is set to 1 after the first NEGL | 
 | 2162 |       // operation. | 
 | 2163 |       __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); | 
 | 2164 |       __ negl(out.AsRegisterPairHigh<Register>()); | 
 | 2165 |       break; | 
 | 2166 |  | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2167 |     case Primitive::kPrimFloat: { | 
 | 2168 |       DCHECK(in.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2169 |       Register constant = locations->GetTemp(0).AsRegister<Register>(); | 
 | 2170 |       XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2171 |       // Implement float negation with an exclusive or with value | 
 | 2172 |       // 0x80000000 (mask for bit 31, representing the sign of a | 
 | 2173 |       // single-precision floating-point number). | 
 | 2174 |       __ movl(constant, Immediate(INT32_C(0x80000000))); | 
 | 2175 |       __ movd(mask, constant); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2176 |       __ xorps(out.AsFpuRegister<XmmRegister>(), mask); | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2177 |       break; | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2178 |     } | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2179 |  | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2180 |     case Primitive::kPrimDouble: { | 
 | 2181 |       DCHECK(in.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2182 |       XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2183 |       // Implement double negation with an exclusive or with value | 
 | 2184 |       // 0x8000000000000000 (mask for bit 63, representing the sign of | 
 | 2185 |       // a double-precision floating-point number). | 
 | 2186 |       __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2187 |       __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2188 |       break; | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2189 |     } | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2190 |  | 
 | 2191 |     default: | 
 | 2192 |       LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); | 
 | 2193 |   } | 
 | 2194 | } | 
 | 2195 |  | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2196 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { | 
 | 2197 |   LocationSummary* locations = | 
 | 2198 |       new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); | 
 | 2199 |   DCHECK(Primitive::IsFloatingPointType(neg->GetType())); | 
 | 2200 |   locations->SetInAt(0, Location::RequiresFpuRegister()); | 
 | 2201 |   locations->SetInAt(1, Location::RequiresRegister()); | 
 | 2202 |   locations->SetOut(Location::SameAsFirstInput()); | 
 | 2203 |   locations->AddTemp(Location::RequiresFpuRegister()); | 
 | 2204 | } | 
 | 2205 |  | 
 | 2206 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { | 
 | 2207 |   LocationSummary* locations = neg->GetLocations(); | 
 | 2208 |   Location out = locations->Out(); | 
 | 2209 |   DCHECK(locations->InAt(0).Equals(out)); | 
 | 2210 |  | 
 | 2211 |   Register constant_area = locations->InAt(1).AsRegister<Register>(); | 
 | 2212 |   XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
 | 2213 |   if (neg->GetType() == Primitive::kPrimFloat) { | 
 | 2214 |     __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); | 
 | 2215 |     __ xorps(out.AsFpuRegister<XmmRegister>(), mask); | 
 | 2216 |   } else { | 
 | 2217 |      __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); | 
 | 2218 |      __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); | 
 | 2219 |   } | 
 | 2220 | } | 
 | 2221 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2222 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2223 |   Primitive::Type result_type = conversion->GetResultType(); | 
 | 2224 |   Primitive::Type input_type = conversion->GetInputType(); | 
| Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2225 |   DCHECK_NE(result_type, input_type); | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2226 |  | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2227 |   // The float-to-long and double-to-long type conversions rely on a | 
 | 2228 |   // call to the runtime. | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2229 |   LocationSummary::CallKind call_kind = | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2230 |       ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) | 
 | 2231 |        && result_type == Primitive::kPrimLong) | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2232 |       ? LocationSummary::kCall | 
 | 2233 |       : LocationSummary::kNoCall; | 
 | 2234 |   LocationSummary* locations = | 
 | 2235 |       new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); | 
 | 2236 |  | 
| David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2237 |   // The Java language does not allow treating boolean as an integral type but | 
 | 2238 |   // our bit representation makes it safe. | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2239 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2240 |   switch (result_type) { | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2241 |     case Primitive::kPrimByte: | 
 | 2242 |       switch (input_type) { | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2243 |         case Primitive::kPrimLong: { | 
 | 2244 |           // Type conversion from long to byte is a result of code transformations. | 
 | 2245 |           HInstruction* input = conversion->InputAt(0); | 
 | 2246 |           Location input_location = input->IsConstant() | 
 | 2247 |               ? Location::ConstantLocation(input->AsConstant()) | 
 | 2248 |               : Location::RegisterPairLocation(EAX, EDX); | 
 | 2249 |           locations->SetInAt(0, input_location); | 
 | 2250 |           // Make the output overlap to please the register allocator. This greatly simplifies | 
 | 2251 |           // the validation of the linear scan implementation | 
 | 2252 |           locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); | 
 | 2253 |           break; | 
 | 2254 |         } | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2255 |         case Primitive::kPrimBoolean: | 
 | 2256 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2257 |         case Primitive::kPrimShort: | 
 | 2258 |         case Primitive::kPrimInt: | 
 | 2259 |         case Primitive::kPrimChar: | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2260 |           // Processing a Dex `int-to-byte' instruction. | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2261 |           locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); | 
 | 2262 |           // Make the output overlap to please the register allocator. This greatly simplifies | 
 | 2263 |           // the validation of the linear scan implementation | 
 | 2264 |           locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2265 |           break; | 
 | 2266 |  | 
 | 2267 |         default: | 
 | 2268 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2269 |                      << " to " << result_type; | 
 | 2270 |       } | 
 | 2271 |       break; | 
 | 2272 |  | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2273 |     case Primitive::kPrimShort: | 
 | 2274 |       switch (input_type) { | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2275 |         case Primitive::kPrimLong: | 
 | 2276 |           // Type conversion from long to short is a result of code transformations. | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2277 |         case Primitive::kPrimBoolean: | 
 | 2278 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2279 |         case Primitive::kPrimByte: | 
 | 2280 |         case Primitive::kPrimInt: | 
 | 2281 |         case Primitive::kPrimChar: | 
 | 2282 |           // Processing a Dex `int-to-short' instruction. | 
 | 2283 |           locations->SetInAt(0, Location::Any()); | 
 | 2284 |           locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
 | 2285 |           break; | 
 | 2286 |  | 
 | 2287 |         default: | 
 | 2288 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2289 |                      << " to " << result_type; | 
 | 2290 |       } | 
 | 2291 |       break; | 
 | 2292 |  | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2293 |     case Primitive::kPrimInt: | 
 | 2294 |       switch (input_type) { | 
 | 2295 |         case Primitive::kPrimLong: | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2296 |           // Processing a Dex `long-to-int' instruction. | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2297 |           locations->SetInAt(0, Location::Any()); | 
 | 2298 |           locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
 | 2299 |           break; | 
 | 2300 |  | 
 | 2301 |         case Primitive::kPrimFloat: | 
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2302 |           // Processing a Dex `float-to-int' instruction. | 
 | 2303 |           locations->SetInAt(0, Location::RequiresFpuRegister()); | 
 | 2304 |           locations->SetOut(Location::RequiresRegister()); | 
 | 2305 |           locations->AddTemp(Location::RequiresFpuRegister()); | 
 | 2306 |           break; | 
 | 2307 |  | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2308 |         case Primitive::kPrimDouble: | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2309 |           // Processing a Dex `double-to-int' instruction. | 
 | 2310 |           locations->SetInAt(0, Location::RequiresFpuRegister()); | 
 | 2311 |           locations->SetOut(Location::RequiresRegister()); | 
 | 2312 |           locations->AddTemp(Location::RequiresFpuRegister()); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2313 |           break; | 
 | 2314 |  | 
 | 2315 |         default: | 
 | 2316 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2317 |                      << " to " << result_type; | 
 | 2318 |       } | 
 | 2319 |       break; | 
 | 2320 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2321 |     case Primitive::kPrimLong: | 
 | 2322 |       switch (input_type) { | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2323 |         case Primitive::kPrimBoolean: | 
 | 2324 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2325 |         case Primitive::kPrimByte: | 
 | 2326 |         case Primitive::kPrimShort: | 
 | 2327 |         case Primitive::kPrimInt: | 
| Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2328 |         case Primitive::kPrimChar: | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2329 |           // Processing a Dex `int-to-long' instruction. | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2330 |           locations->SetInAt(0, Location::RegisterLocation(EAX)); | 
 | 2331 |           locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); | 
 | 2332 |           break; | 
 | 2333 |  | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2334 |         case Primitive::kPrimFloat: | 
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2335 |         case Primitive::kPrimDouble: { | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2336 |           // Processing a Dex `float-to-long' or 'double-to-long' instruction. | 
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2337 |           InvokeRuntimeCallingConvention calling_convention; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2338 |           XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); | 
 | 2339 |           locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); | 
 | 2340 |  | 
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2341 |           // The runtime helper puts the result in EAX, EDX. | 
 | 2342 |           locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); | 
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2343 |         } | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2344 |         break; | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2345 |  | 
 | 2346 |         default: | 
 | 2347 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2348 |                      << " to " << result_type; | 
 | 2349 |       } | 
 | 2350 |       break; | 
 | 2351 |  | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2352 |     case Primitive::kPrimChar: | 
 | 2353 |       switch (input_type) { | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2354 |         case Primitive::kPrimLong: | 
 | 2355 |           // Type conversion from long to char is a result of code transformations. | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2356 |         case Primitive::kPrimBoolean: | 
 | 2357 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2358 |         case Primitive::kPrimByte: | 
 | 2359 |         case Primitive::kPrimShort: | 
 | 2360 |         case Primitive::kPrimInt: | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2361 |           // Processing a Dex `int-to-char' instruction. | 
 | 2362 |           locations->SetInAt(0, Location::Any()); | 
 | 2363 |           locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
 | 2364 |           break; | 
 | 2365 |  | 
 | 2366 |         default: | 
 | 2367 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2368 |                      << " to " << result_type; | 
 | 2369 |       } | 
 | 2370 |       break; | 
 | 2371 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2372 |     case Primitive::kPrimFloat: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2373 |       switch (input_type) { | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2374 |         case Primitive::kPrimBoolean: | 
 | 2375 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2376 |         case Primitive::kPrimByte: | 
 | 2377 |         case Primitive::kPrimShort: | 
 | 2378 |         case Primitive::kPrimInt: | 
 | 2379 |         case Primitive::kPrimChar: | 
 | 2380 |           // Processing a Dex `int-to-float' instruction. | 
 | 2381 |           locations->SetInAt(0, Location::RequiresRegister()); | 
 | 2382 |           locations->SetOut(Location::RequiresFpuRegister()); | 
 | 2383 |           break; | 
 | 2384 |  | 
 | 2385 |         case Primitive::kPrimLong: | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2386 |           // Processing a Dex `long-to-float' instruction. | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2387 |           locations->SetInAt(0, Location::Any()); | 
 | 2388 |           locations->SetOut(Location::Any()); | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2389 |           break; | 
 | 2390 |  | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2391 |         case Primitive::kPrimDouble: | 
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2392 |           // Processing a Dex `double-to-float' instruction. | 
 | 2393 |           locations->SetInAt(0, Location::RequiresFpuRegister()); | 
 | 2394 |           locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2395 |           break; | 
 | 2396 |  | 
 | 2397 |         default: | 
 | 2398 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2399 |                      << " to " << result_type; | 
 | 2400 |       }; | 
 | 2401 |       break; | 
 | 2402 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2403 |     case Primitive::kPrimDouble: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2404 |       switch (input_type) { | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2405 |         case Primitive::kPrimBoolean: | 
 | 2406 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2407 |         case Primitive::kPrimByte: | 
 | 2408 |         case Primitive::kPrimShort: | 
 | 2409 |         case Primitive::kPrimInt: | 
 | 2410 |         case Primitive::kPrimChar: | 
 | 2411 |           // Processing a Dex `int-to-double' instruction. | 
 | 2412 |           locations->SetInAt(0, Location::RequiresRegister()); | 
 | 2413 |           locations->SetOut(Location::RequiresFpuRegister()); | 
 | 2414 |           break; | 
 | 2415 |  | 
 | 2416 |         case Primitive::kPrimLong: | 
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2417 |           // Processing a Dex `long-to-double' instruction. | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2418 |           locations->SetInAt(0, Location::Any()); | 
 | 2419 |           locations->SetOut(Location::Any()); | 
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2420 |           break; | 
 | 2421 |  | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2422 |         case Primitive::kPrimFloat: | 
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2423 |           // Processing a Dex `float-to-double' instruction. | 
 | 2424 |           locations->SetInAt(0, Location::RequiresFpuRegister()); | 
 | 2425 |           locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2426 |           break; | 
 | 2427 |  | 
 | 2428 |         default: | 
 | 2429 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2430 |                      << " to " << result_type; | 
 | 2431 |       } | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2432 |       break; | 
 | 2433 |  | 
 | 2434 |     default: | 
 | 2435 |       LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2436 |                  << " to " << result_type; | 
 | 2437 |   } | 
 | 2438 | } | 
 | 2439 |  | 
 | 2440 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { | 
 | 2441 |   LocationSummary* locations = conversion->GetLocations(); | 
 | 2442 |   Location out = locations->Out(); | 
 | 2443 |   Location in = locations->InAt(0); | 
 | 2444 |   Primitive::Type result_type = conversion->GetResultType(); | 
 | 2445 |   Primitive::Type input_type = conversion->GetInputType(); | 
| Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2446 |   DCHECK_NE(result_type, input_type); | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2447 |   switch (result_type) { | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2448 |     case Primitive::kPrimByte: | 
 | 2449 |       switch (input_type) { | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2450 |         case Primitive::kPrimLong: | 
 | 2451 |           // Type conversion from long to byte is a result of code transformations. | 
 | 2452 |           if (in.IsRegisterPair()) { | 
 | 2453 |             __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); | 
 | 2454 |           } else { | 
 | 2455 |             DCHECK(in.GetConstant()->IsLongConstant()); | 
 | 2456 |             int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); | 
 | 2457 |             __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); | 
 | 2458 |           } | 
 | 2459 |           break; | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2460 |         case Primitive::kPrimBoolean: | 
 | 2461 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2462 |         case Primitive::kPrimShort: | 
 | 2463 |         case Primitive::kPrimInt: | 
 | 2464 |         case Primitive::kPrimChar: | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2465 |           // Processing a Dex `int-to-byte' instruction. | 
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2466 |           if (in.IsRegister()) { | 
 | 2467 |             __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); | 
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2468 |           } else { | 
 | 2469 |             DCHECK(in.GetConstant()->IsIntConstant()); | 
 | 2470 |             int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); | 
 | 2471 |             __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); | 
 | 2472 |           } | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2473 |           break; | 
 | 2474 |  | 
 | 2475 |         default: | 
 | 2476 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2477 |                      << " to " << result_type; | 
 | 2478 |       } | 
 | 2479 |       break; | 
 | 2480 |  | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2481 |     case Primitive::kPrimShort: | 
 | 2482 |       switch (input_type) { | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2483 |         case Primitive::kPrimLong: | 
 | 2484 |           // Type conversion from long to short is a result of code transformations. | 
 | 2485 |           if (in.IsRegisterPair()) { | 
 | 2486 |             __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); | 
 | 2487 |           } else if (in.IsDoubleStackSlot()) { | 
 | 2488 |             __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
 | 2489 |           } else { | 
 | 2490 |             DCHECK(in.GetConstant()->IsLongConstant()); | 
 | 2491 |             int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); | 
 | 2492 |             __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); | 
 | 2493 |           } | 
 | 2494 |           break; | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2495 |         case Primitive::kPrimBoolean: | 
 | 2496 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2497 |         case Primitive::kPrimByte: | 
 | 2498 |         case Primitive::kPrimInt: | 
 | 2499 |         case Primitive::kPrimChar: | 
 | 2500 |           // Processing a Dex `int-to-short' instruction. | 
 | 2501 |           if (in.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2502 |             __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2503 |           } else if (in.IsStackSlot()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2504 |             __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2505 |           } else { | 
 | 2506 |             DCHECK(in.GetConstant()->IsIntConstant()); | 
 | 2507 |             int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2508 |             __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2509 |           } | 
 | 2510 |           break; | 
 | 2511 |  | 
 | 2512 |         default: | 
 | 2513 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2514 |                      << " to " << result_type; | 
 | 2515 |       } | 
 | 2516 |       break; | 
 | 2517 |  | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2518 |     case Primitive::kPrimInt: | 
 | 2519 |       switch (input_type) { | 
 | 2520 |         case Primitive::kPrimLong: | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2521 |           // Processing a Dex `long-to-int' instruction. | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2522 |           if (in.IsRegisterPair()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2523 |             __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2524 |           } else if (in.IsDoubleStackSlot()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2525 |             __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2526 |           } else { | 
 | 2527 |             DCHECK(in.IsConstant()); | 
 | 2528 |             DCHECK(in.GetConstant()->IsLongConstant()); | 
 | 2529 |             int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2530 |             __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2531 |           } | 
 | 2532 |           break; | 
 | 2533 |  | 
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2534 |         case Primitive::kPrimFloat: { | 
 | 2535 |           // Processing a Dex `float-to-int' instruction. | 
 | 2536 |           XmmRegister input = in.AsFpuRegister<XmmRegister>(); | 
 | 2537 |           Register output = out.AsRegister<Register>(); | 
 | 2538 |           XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2539 |           NearLabel done, nan; | 
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2540 |  | 
 | 2541 |           __ movl(output, Immediate(kPrimIntMax)); | 
 | 2542 |           // temp = int-to-float(output) | 
 | 2543 |           __ cvtsi2ss(temp, output); | 
 | 2544 |           // if input >= temp goto done | 
 | 2545 |           __ comiss(input, temp); | 
 | 2546 |           __ j(kAboveEqual, &done); | 
 | 2547 |           // if input == NaN goto nan | 
 | 2548 |           __ j(kUnordered, &nan); | 
 | 2549 |           // output = float-to-int-truncate(input) | 
 | 2550 |           __ cvttss2si(output, input); | 
 | 2551 |           __ jmp(&done); | 
 | 2552 |           __ Bind(&nan); | 
 | 2553 |           //  output = 0 | 
 | 2554 |           __ xorl(output, output); | 
 | 2555 |           __ Bind(&done); | 
 | 2556 |           break; | 
 | 2557 |         } | 
 | 2558 |  | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2559 |         case Primitive::kPrimDouble: { | 
 | 2560 |           // Processing a Dex `double-to-int' instruction. | 
 | 2561 |           XmmRegister input = in.AsFpuRegister<XmmRegister>(); | 
 | 2562 |           Register output = out.AsRegister<Register>(); | 
 | 2563 |           XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2564 |           NearLabel done, nan; | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2565 |  | 
 | 2566 |           __ movl(output, Immediate(kPrimIntMax)); | 
 | 2567 |           // temp = int-to-double(output) | 
 | 2568 |           __ cvtsi2sd(temp, output); | 
 | 2569 |           // if input >= temp goto done | 
 | 2570 |           __ comisd(input, temp); | 
 | 2571 |           __ j(kAboveEqual, &done); | 
 | 2572 |           // if input == NaN goto nan | 
 | 2573 |           __ j(kUnordered, &nan); | 
 | 2574 |           // output = double-to-int-truncate(input) | 
 | 2575 |           __ cvttsd2si(output, input); | 
 | 2576 |           __ jmp(&done); | 
 | 2577 |           __ Bind(&nan); | 
 | 2578 |           //  output = 0 | 
 | 2579 |           __ xorl(output, output); | 
 | 2580 |           __ Bind(&done); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2581 |           break; | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2582 |         } | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2583 |  | 
 | 2584 |         default: | 
 | 2585 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2586 |                      << " to " << result_type; | 
 | 2587 |       } | 
 | 2588 |       break; | 
 | 2589 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2590 |     case Primitive::kPrimLong: | 
 | 2591 |       switch (input_type) { | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2592 |         case Primitive::kPrimBoolean: | 
 | 2593 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2594 |         case Primitive::kPrimByte: | 
 | 2595 |         case Primitive::kPrimShort: | 
 | 2596 |         case Primitive::kPrimInt: | 
| Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2597 |         case Primitive::kPrimChar: | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2598 |           // Processing a Dex `int-to-long' instruction. | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2599 |           DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); | 
 | 2600 |           DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2601 |           DCHECK_EQ(in.AsRegister<Register>(), EAX); | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2602 |           __ cdq(); | 
 | 2603 |           break; | 
 | 2604 |  | 
 | 2605 |         case Primitive::kPrimFloat: | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2606 |           // Processing a Dex `float-to-long' instruction. | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2607 |           codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), | 
 | 2608 |                                   conversion, | 
 | 2609 |                                   conversion->GetDexPc(), | 
 | 2610 |                                   nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2611 |           CheckEntrypointTypes<kQuickF2l, int64_t, float>(); | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2612 |           break; | 
 | 2613 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2614 |         case Primitive::kPrimDouble: | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2615 |           // Processing a Dex `double-to-long' instruction. | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2616 |           codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), | 
 | 2617 |                                   conversion, | 
 | 2618 |                                   conversion->GetDexPc(), | 
 | 2619 |                                   nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2620 |           CheckEntrypointTypes<kQuickD2l, int64_t, double>(); | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2621 |           break; | 
 | 2622 |  | 
 | 2623 |         default: | 
 | 2624 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2625 |                      << " to " << result_type; | 
 | 2626 |       } | 
 | 2627 |       break; | 
 | 2628 |  | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2629 |     case Primitive::kPrimChar: | 
 | 2630 |       switch (input_type) { | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2631 |         case Primitive::kPrimLong: | 
 | 2632 |           // Type conversion from long to short is a result of code transformations. | 
 | 2633 |           if (in.IsRegisterPair()) { | 
 | 2634 |             __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); | 
 | 2635 |           } else if (in.IsDoubleStackSlot()) { | 
 | 2636 |             __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
 | 2637 |           } else { | 
 | 2638 |             DCHECK(in.GetConstant()->IsLongConstant()); | 
 | 2639 |             int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); | 
 | 2640 |             __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); | 
 | 2641 |           } | 
 | 2642 |           break; | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2643 |         case Primitive::kPrimBoolean: | 
 | 2644 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2645 |         case Primitive::kPrimByte: | 
 | 2646 |         case Primitive::kPrimShort: | 
 | 2647 |         case Primitive::kPrimInt: | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2648 |           // Processing a Dex `Process a Dex `int-to-char'' instruction. | 
 | 2649 |           if (in.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2650 |             __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2651 |           } else if (in.IsStackSlot()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2652 |             __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2653 |           } else { | 
 | 2654 |             DCHECK(in.GetConstant()->IsIntConstant()); | 
 | 2655 |             int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2656 |             __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); | 
| Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2657 |           } | 
 | 2658 |           break; | 
 | 2659 |  | 
 | 2660 |         default: | 
 | 2661 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2662 |                      << " to " << result_type; | 
 | 2663 |       } | 
 | 2664 |       break; | 
 | 2665 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2666 |     case Primitive::kPrimFloat: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 |       switch (input_type) { | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2668 |         case Primitive::kPrimBoolean: | 
 | 2669 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2670 |         case Primitive::kPrimByte: | 
 | 2671 |         case Primitive::kPrimShort: | 
 | 2672 |         case Primitive::kPrimInt: | 
 | 2673 |         case Primitive::kPrimChar: | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2674 |           // Processing a Dex `int-to-float' instruction. | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2675 |           __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2676 |           break; | 
 | 2677 |  | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2678 |         case Primitive::kPrimLong: { | 
 | 2679 |           // Processing a Dex `long-to-float' instruction. | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2680 |           size_t adjustment = 0; | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2681 |  | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2682 |           // Create stack space for the call to | 
 | 2683 |           // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. | 
 | 2684 |           // TODO: enhance register allocator to ask for stack temporaries. | 
 | 2685 |           if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { | 
 | 2686 |             adjustment = Primitive::ComponentSize(Primitive::kPrimLong); | 
 | 2687 |             __ subl(ESP, Immediate(adjustment)); | 
 | 2688 |           } | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2689 |  | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2690 |           // Load the value to the FP stack, using temporaries if needed. | 
 | 2691 |           PushOntoFPStack(in, 0, adjustment, false, true); | 
 | 2692 |  | 
 | 2693 |           if (out.IsStackSlot()) { | 
 | 2694 |             __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); | 
 | 2695 |           } else { | 
 | 2696 |             __ fstps(Address(ESP, 0)); | 
 | 2697 |             Location stack_temp = Location::StackSlot(0); | 
 | 2698 |             codegen_->Move32(out, stack_temp); | 
 | 2699 |           } | 
 | 2700 |  | 
 | 2701 |           // Remove the temporary stack space we allocated. | 
 | 2702 |           if (adjustment != 0) { | 
 | 2703 |             __ addl(ESP, Immediate(adjustment)); | 
 | 2704 |           } | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2705 |           break; | 
 | 2706 |         } | 
 | 2707 |  | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2708 |         case Primitive::kPrimDouble: | 
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2709 |           // Processing a Dex `double-to-float' instruction. | 
 | 2710 |           __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2711 |           break; | 
 | 2712 |  | 
 | 2713 |         default: | 
 | 2714 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2715 |                      << " to " << result_type; | 
 | 2716 |       }; | 
 | 2717 |       break; | 
 | 2718 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2719 |     case Primitive::kPrimDouble: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2720 |       switch (input_type) { | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2721 |         case Primitive::kPrimBoolean: | 
 | 2722 |           // Boolean input is a result of code transformations. | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2723 |         case Primitive::kPrimByte: | 
 | 2724 |         case Primitive::kPrimShort: | 
 | 2725 |         case Primitive::kPrimInt: | 
 | 2726 |         case Primitive::kPrimChar: | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2727 |           // Processing a Dex `int-to-double' instruction. | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2728 |           __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2729 |           break; | 
 | 2730 |  | 
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2731 |         case Primitive::kPrimLong: { | 
 | 2732 |           // Processing a Dex `long-to-double' instruction. | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2733 |           size_t adjustment = 0; | 
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2734 |  | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2735 |           // Create stack space for the call to | 
 | 2736 |           // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. | 
 | 2737 |           // TODO: enhance register allocator to ask for stack temporaries. | 
 | 2738 |           if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { | 
 | 2739 |             adjustment = Primitive::ComponentSize(Primitive::kPrimLong); | 
 | 2740 |             __ subl(ESP, Immediate(adjustment)); | 
 | 2741 |           } | 
 | 2742 |  | 
 | 2743 |           // Load the value to the FP stack, using temporaries if needed. | 
 | 2744 |           PushOntoFPStack(in, 0, adjustment, false, true); | 
 | 2745 |  | 
 | 2746 |           if (out.IsDoubleStackSlot()) { | 
 | 2747 |             __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); | 
 | 2748 |           } else { | 
 | 2749 |             __ fstpl(Address(ESP, 0)); | 
 | 2750 |             Location stack_temp = Location::DoubleStackSlot(0); | 
 | 2751 |             codegen_->Move64(out, stack_temp); | 
 | 2752 |           } | 
 | 2753 |  | 
 | 2754 |           // Remove the temporary stack space we allocated. | 
 | 2755 |           if (adjustment != 0) { | 
 | 2756 |             __ addl(ESP, Immediate(adjustment)); | 
 | 2757 |           } | 
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2758 |           break; | 
 | 2759 |         } | 
 | 2760 |  | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2761 |         case Primitive::kPrimFloat: | 
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2762 |           // Processing a Dex `float-to-double' instruction. | 
 | 2763 |           __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2764 |           break; | 
 | 2765 |  | 
 | 2766 |         default: | 
 | 2767 |           LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2768 |                      << " to " << result_type; | 
 | 2769 |       }; | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2770 |       break; | 
 | 2771 |  | 
 | 2772 |     default: | 
 | 2773 |       LOG(FATAL) << "Unexpected type conversion from " << input_type | 
 | 2774 |                  << " to " << result_type; | 
 | 2775 |   } | 
 | 2776 | } | 
 | 2777 |  | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2778 | void LocationsBuilderX86::VisitAdd(HAdd* add) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2779 |   LocationSummary* locations = | 
 | 2780 |       new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2781 |   switch (add->GetResultType()) { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2782 |     case Primitive::kPrimInt: { | 
 | 2783 |       locations->SetInAt(0, Location::RequiresRegister()); | 
 | 2784 |       locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); | 
 | 2785 |       locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
 | 2786 |       break; | 
 | 2787 |     } | 
 | 2788 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2789 |     case Primitive::kPrimLong: { | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2790 |       locations->SetInAt(0, Location::RequiresRegister()); | 
 | 2791 |       locations->SetInAt(1, Location::Any()); | 
 | 2792 |       locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2793 |       break; | 
 | 2794 |     } | 
 | 2795 |  | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2796 |     case Primitive::kPrimFloat: | 
 | 2797 |     case Primitive::kPrimDouble: { | 
 | 2798 |       locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2799 |       if (add->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 2800 |         DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); | 
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2801 |       } else if (add->InputAt(1)->IsConstant()) { | 
 | 2802 |         locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2803 |       } else { | 
 | 2804 |         locations->SetInAt(1, Location::Any()); | 
 | 2805 |       } | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2806 |       locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2807 |       break; | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2808 |     } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2809 |  | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2810 |     default: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2811 |       LOG(FATAL) << "Unexpected add type " << add->GetResultType(); | 
 | 2812 |       break; | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2813 |   } | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2814 | } | 
 | 2815 |  | 
 | 2816 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { | 
 | 2817 |   LocationSummary* locations = add->GetLocations(); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2818 |   Location first = locations->InAt(0); | 
 | 2819 |   Location second = locations->InAt(1); | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2820 |   Location out = locations->Out(); | 
 | 2821 |  | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2822 |   switch (add->GetResultType()) { | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2823 |     case Primitive::kPrimInt: { | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2824 |       if (second.IsRegister()) { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2825 |         if (out.AsRegister<Register>() == first.AsRegister<Register>()) { | 
 | 2826 |           __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2827 |         } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { | 
 | 2828 |           __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2829 |         } else { | 
 | 2830 |           __ leal(out.AsRegister<Register>(), Address( | 
 | 2831 |               first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); | 
 | 2832 |           } | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2833 |       } else if (second.IsConstant()) { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2834 |         int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); | 
 | 2835 |         if (out.AsRegister<Register>() == first.AsRegister<Register>()) { | 
 | 2836 |           __ addl(out.AsRegister<Register>(), Immediate(value)); | 
 | 2837 |         } else { | 
 | 2838 |           __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); | 
 | 2839 |         } | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2840 |       } else { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2841 |         DCHECK(first.Equals(locations->Out())); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2842 |         __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2843 |       } | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2844 |       break; | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2845 |     } | 
 | 2846 |  | 
 | 2847 |     case Primitive::kPrimLong: { | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2848 |       if (second.IsRegisterPair()) { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2849 |         __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
 | 2850 |         __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2851 |       } else if (second.IsDoubleStackSlot()) { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2852 |         __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
 | 2853 |         __ adcl(first.AsRegisterPairHigh<Register>(), | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2854 |                 Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2855 |       } else { | 
 | 2856 |         DCHECK(second.IsConstant()) << second; | 
 | 2857 |         int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); | 
 | 2858 |         __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); | 
 | 2859 |         __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2860 |       } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2861 |       break; | 
 | 2862 |     } | 
 | 2863 |  | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2864 |     case Primitive::kPrimFloat: { | 
 | 2865 |       if (second.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2866 |         __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2867 |       } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 2868 |         HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2869 |         DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2870 |         __ addss(first.AsFpuRegister<XmmRegister>(), | 
 | 2871 |                  codegen_->LiteralFloatAddress( | 
 | 2872 |                    const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
 | 2873 |                    const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 2874 |       } else { | 
 | 2875 |         DCHECK(second.IsStackSlot()); | 
 | 2876 |         __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2877 |       } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2878 |       break; | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2879 |     } | 
 | 2880 |  | 
 | 2881 |     case Primitive::kPrimDouble: { | 
 | 2882 |       if (second.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2883 |         __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2884 |       } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 2885 |         HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2886 |         DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2887 |         __ addsd(first.AsFpuRegister<XmmRegister>(), | 
 | 2888 |                  codegen_->LiteralDoubleAddress( | 
 | 2889 |                    const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
 | 2890 |                    const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 2891 |       } else { | 
 | 2892 |         DCHECK(second.IsDoubleStackSlot()); | 
 | 2893 |         __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2894 |       } | 
 | 2895 |       break; | 
 | 2896 |     } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2897 |  | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2898 |     default: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2899 |       LOG(FATAL) << "Unexpected add type " << add->GetResultType(); | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2900 |   } | 
 | 2901 | } | 
 | 2902 |  | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2903 | void LocationsBuilderX86::VisitSub(HSub* sub) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2904 |   LocationSummary* locations = | 
 | 2905 |       new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2906 |   switch (sub->GetResultType()) { | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2907 |     case Primitive::kPrimInt: | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2908 |     case Primitive::kPrimLong: { | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2909 |       locations->SetInAt(0, Location::RequiresRegister()); | 
 | 2910 |       locations->SetInAt(1, Location::Any()); | 
 | 2911 |       locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2912 |       break; | 
 | 2913 |     } | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2914 |     case Primitive::kPrimFloat: | 
 | 2915 |     case Primitive::kPrimDouble: { | 
 | 2916 |       locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2917 |       if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 2918 |         DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); | 
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2919 |       } else if (sub->InputAt(1)->IsConstant()) { | 
 | 2920 |         locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2921 |       } else { | 
 | 2922 |         locations->SetInAt(1, Location::Any()); | 
 | 2923 |       } | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2924 |       locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2925 |       break; | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2926 |     } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2927 |  | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2928 |     default: | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2929 |       LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2930 |   } | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2931 | } | 
 | 2932 |  | 
 | 2933 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { | 
 | 2934 |   LocationSummary* locations = sub->GetLocations(); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2935 |   Location first = locations->InAt(0); | 
 | 2936 |   Location second = locations->InAt(1); | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2937 |   DCHECK(first.Equals(locations->Out())); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2938 |   switch (sub->GetResultType()) { | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2939 |     case Primitive::kPrimInt: { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2940 |       if (second.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2941 |         __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2942 |       } else if (second.IsConstant()) { | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2943 |         __ subl(first.AsRegister<Register>(), | 
 | 2944 |                 Immediate(second.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2945 |       } else { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2946 |         __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2947 |       } | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2948 |       break; | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2949 |     } | 
 | 2950 |  | 
 | 2951 |     case Primitive::kPrimLong: { | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2952 |       if (second.IsRegisterPair()) { | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2953 |         __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
 | 2954 |         __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2955 |       } else if (second.IsDoubleStackSlot()) { | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2956 |         __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2957 |         __ sbbl(first.AsRegisterPairHigh<Register>(), | 
 | 2958 |                 Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2959 |       } else { | 
 | 2960 |         DCHECK(second.IsConstant()) << second; | 
 | 2961 |         int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); | 
 | 2962 |         __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); | 
 | 2963 |         __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2964 |       } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2965 |       break; | 
 | 2966 |     } | 
 | 2967 |  | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2968 |     case Primitive::kPrimFloat: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2969 |       if (second.IsFpuRegister()) { | 
 | 2970 |         __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
 | 2971 |       } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 2972 |         HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2973 |         DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2974 |         __ subss(first.AsFpuRegister<XmmRegister>(), | 
 | 2975 |                  codegen_->LiteralFloatAddress( | 
 | 2976 |                    const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
 | 2977 |                    const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 2978 |       } else { | 
 | 2979 |         DCHECK(second.IsStackSlot()); | 
 | 2980 |         __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
 | 2981 |       } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2982 |       break; | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2983 |     } | 
 | 2984 |  | 
 | 2985 |     case Primitive::kPrimDouble: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2986 |       if (second.IsFpuRegister()) { | 
 | 2987 |         __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
 | 2988 |       } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 2989 |         HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2990 |         DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2991 |         __ subsd(first.AsFpuRegister<XmmRegister>(), | 
 | 2992 |                  codegen_->LiteralDoubleAddress( | 
 | 2993 |                      const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
 | 2994 |                      const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 2995 |       } else { | 
 | 2996 |         DCHECK(second.IsDoubleStackSlot()); | 
 | 2997 |         __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
 | 2998 |       } | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2999 |       break; | 
 | 3000 |     } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3001 |  | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3002 |     default: | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3003 |       LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3004 |   } | 
 | 3005 | } | 
 | 3006 |  | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3007 | void LocationsBuilderX86::VisitMul(HMul* mul) { | 
 | 3008 |   LocationSummary* locations = | 
 | 3009 |       new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); | 
 | 3010 |   switch (mul->GetResultType()) { | 
 | 3011 |     case Primitive::kPrimInt: | 
 | 3012 |       locations->SetInAt(0, Location::RequiresRegister()); | 
 | 3013 |       locations->SetInAt(1, Location::Any()); | 
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3014 |       if (mul->InputAt(1)->IsIntConstant()) { | 
 | 3015 |         // Can use 3 operand multiply. | 
 | 3016 |         locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
 | 3017 |       } else { | 
 | 3018 |         locations->SetOut(Location::SameAsFirstInput()); | 
 | 3019 |       } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3020 |       break; | 
 | 3021 |     case Primitive::kPrimLong: { | 
 | 3022 |       locations->SetInAt(0, Location::RequiresRegister()); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3023 |       locations->SetInAt(1, Location::Any()); | 
 | 3024 |       locations->SetOut(Location::SameAsFirstInput()); | 
 | 3025 |       // Needed for imul on 32bits with 64bits output. | 
 | 3026 |       locations->AddTemp(Location::RegisterLocation(EAX)); | 
 | 3027 |       locations->AddTemp(Location::RegisterLocation(EDX)); | 
 | 3028 |       break; | 
 | 3029 |     } | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3030 |     case Primitive::kPrimFloat: | 
 | 3031 |     case Primitive::kPrimDouble: { | 
 | 3032 |       locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3033 |       if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 3034 |         DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); | 
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3035 |       } else if (mul->InputAt(1)->IsConstant()) { | 
 | 3036 |         locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3037 |       } else { | 
 | 3038 |         locations->SetInAt(1, Location::Any()); | 
 | 3039 |       } | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3040 |       locations->SetOut(Location::SameAsFirstInput()); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3041 |       break; | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3042 |     } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3043 |  | 
 | 3044 |     default: | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3045 |       LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3046 |   } | 
 | 3047 | } | 
 | 3048 |  | 
 | 3049 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { | 
 | 3050 |   LocationSummary* locations = mul->GetLocations(); | 
 | 3051 |   Location first = locations->InAt(0); | 
 | 3052 |   Location second = locations->InAt(1); | 
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3053 |   Location out = locations->Out(); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3054 |  | 
 | 3055 |   switch (mul->GetResultType()) { | 
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3056 |     case Primitive::kPrimInt: | 
 | 3057 |       // The constant may have ended up in a register, so test explicitly to avoid | 
 | 3058 |       // problems where the output may not be the same as the first operand. | 
 | 3059 |       if (mul->InputAt(1)->IsIntConstant()) { | 
 | 3060 |         Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); | 
 | 3061 |         __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); | 
 | 3062 |       } else if (second.IsRegister()) { | 
 | 3063 |         DCHECK(first.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3064 |         __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3065 |       } else { | 
 | 3066 |         DCHECK(second.IsStackSlot()); | 
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3067 |         DCHECK(first.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3068 |         __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3069 |       } | 
 | 3070 |       break; | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3071 |  | 
 | 3072 |     case Primitive::kPrimLong: { | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3073 |       Register in1_hi = first.AsRegisterPairHigh<Register>(); | 
 | 3074 |       Register in1_lo = first.AsRegisterPairLow<Register>(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3075 |       Register eax = locations->GetTemp(0).AsRegister<Register>(); | 
 | 3076 |       Register edx = locations->GetTemp(1).AsRegister<Register>(); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3077 |  | 
 | 3078 |       DCHECK_EQ(EAX, eax); | 
 | 3079 |       DCHECK_EQ(EDX, edx); | 
 | 3080 |  | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3081 |       // input: in1 - 64 bits, in2 - 64 bits. | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3082 |       // output: in1 | 
 | 3083 |       // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo | 
 | 3084 |       // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] | 
 | 3085 |       // parts: in1.lo = (in1.lo * in2.lo)[31:0] | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3086 |       if (second.IsConstant()) { | 
 | 3087 |         DCHECK(second.GetConstant()->IsLongConstant()); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3088 |  | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3089 |         int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); | 
 | 3090 |         int32_t low_value = Low32Bits(value); | 
 | 3091 |         int32_t high_value = High32Bits(value); | 
 | 3092 |         Immediate low(low_value); | 
 | 3093 |         Immediate high(high_value); | 
 | 3094 |  | 
 | 3095 |         __ movl(eax, high); | 
 | 3096 |         // eax <- in1.lo * in2.hi | 
 | 3097 |         __ imull(eax, in1_lo); | 
 | 3098 |         // in1.hi <- in1.hi * in2.lo | 
 | 3099 |         __ imull(in1_hi, low); | 
 | 3100 |         // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo | 
 | 3101 |         __ addl(in1_hi, eax); | 
 | 3102 |         // move in2_lo to eax to prepare for double precision | 
 | 3103 |         __ movl(eax, low); | 
 | 3104 |         // edx:eax <- in1.lo * in2.lo | 
 | 3105 |         __ mull(in1_lo); | 
 | 3106 |         // in1.hi <- in2.hi * in1.lo +  in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] | 
 | 3107 |         __ addl(in1_hi, edx); | 
 | 3108 |         // in1.lo <- (in1.lo * in2.lo)[31:0]; | 
 | 3109 |         __ movl(in1_lo, eax); | 
 | 3110 |       } else if (second.IsRegisterPair()) { | 
 | 3111 |         Register in2_hi = second.AsRegisterPairHigh<Register>(); | 
 | 3112 |         Register in2_lo = second.AsRegisterPairLow<Register>(); | 
 | 3113 |  | 
 | 3114 |         __ movl(eax, in2_hi); | 
 | 3115 |         // eax <- in1.lo * in2.hi | 
 | 3116 |         __ imull(eax, in1_lo); | 
 | 3117 |         // in1.hi <- in1.hi * in2.lo | 
 | 3118 |         __ imull(in1_hi, in2_lo); | 
 | 3119 |         // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo | 
 | 3120 |         __ addl(in1_hi, eax); | 
 | 3121 |         // move in1_lo to eax to prepare for double precision | 
 | 3122 |         __ movl(eax, in1_lo); | 
 | 3123 |         // edx:eax <- in1.lo * in2.lo | 
 | 3124 |         __ mull(in2_lo); | 
 | 3125 |         // in1.hi <- in2.hi * in1.lo +  in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] | 
 | 3126 |         __ addl(in1_hi, edx); | 
 | 3127 |         // in1.lo <- (in1.lo * in2.lo)[31:0]; | 
 | 3128 |         __ movl(in1_lo, eax); | 
 | 3129 |       } else { | 
 | 3130 |         DCHECK(second.IsDoubleStackSlot()) << second; | 
 | 3131 |         Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); | 
 | 3132 |         Address in2_lo(ESP, second.GetStackIndex()); | 
 | 3133 |  | 
 | 3134 |         __ movl(eax, in2_hi); | 
 | 3135 |         // eax <- in1.lo * in2.hi | 
 | 3136 |         __ imull(eax, in1_lo); | 
 | 3137 |         // in1.hi <- in1.hi * in2.lo | 
 | 3138 |         __ imull(in1_hi, in2_lo); | 
 | 3139 |         // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo | 
 | 3140 |         __ addl(in1_hi, eax); | 
 | 3141 |         // move in1_lo to eax to prepare for double precision | 
 | 3142 |         __ movl(eax, in1_lo); | 
 | 3143 |         // edx:eax <- in1.lo * in2.lo | 
 | 3144 |         __ mull(in2_lo); | 
 | 3145 |         // in1.hi <- in2.hi * in1.lo +  in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] | 
 | 3146 |         __ addl(in1_hi, edx); | 
 | 3147 |         // in1.lo <- (in1.lo * in2.lo)[31:0]; | 
 | 3148 |         __ movl(in1_lo, eax); | 
 | 3149 |       } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3150 |  | 
 | 3151 |       break; | 
 | 3152 |     } | 
 | 3153 |  | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3154 |     case Primitive::kPrimFloat: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3155 |       DCHECK(first.Equals(locations->Out())); | 
 | 3156 |       if (second.IsFpuRegister()) { | 
 | 3157 |         __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
 | 3158 |       } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 3159 |         HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3160 |         DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3161 |         __ mulss(first.AsFpuRegister<XmmRegister>(), | 
 | 3162 |                  codegen_->LiteralFloatAddress( | 
 | 3163 |                      const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
 | 3164 |                      const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 3165 |       } else { | 
 | 3166 |         DCHECK(second.IsStackSlot()); | 
 | 3167 |         __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
 | 3168 |       } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3169 |       break; | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3170 |     } | 
 | 3171 |  | 
 | 3172 |     case Primitive::kPrimDouble: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3173 |       DCHECK(first.Equals(locations->Out())); | 
 | 3174 |       if (second.IsFpuRegister()) { | 
 | 3175 |         __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
 | 3176 |       } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 3177 |         HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3178 |         DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3179 |         __ mulsd(first.AsFpuRegister<XmmRegister>(), | 
 | 3180 |                  codegen_->LiteralDoubleAddress( | 
 | 3181 |                      const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
 | 3182 |                      const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 3183 |       } else { | 
 | 3184 |         DCHECK(second.IsDoubleStackSlot()); | 
 | 3185 |         __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
 | 3186 |       } | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3187 |       break; | 
 | 3188 |     } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3189 |  | 
 | 3190 |     default: | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3191 |       LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3192 |   } | 
 | 3193 | } | 
 | 3194 |  | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3195 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, | 
 | 3196 |                                                   uint32_t temp_offset, | 
 | 3197 |                                                   uint32_t stack_adjustment, | 
 | 3198 |                                                   bool is_fp, | 
 | 3199 |                                                   bool is_wide) { | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3200 |   if (source.IsStackSlot()) { | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3201 |     DCHECK(!is_wide); | 
 | 3202 |     if (is_fp) { | 
 | 3203 |       __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); | 
 | 3204 |     } else { | 
 | 3205 |       __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); | 
 | 3206 |     } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3207 |   } else if (source.IsDoubleStackSlot()) { | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3208 |     DCHECK(is_wide); | 
 | 3209 |     if (is_fp) { | 
 | 3210 |       __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); | 
 | 3211 |     } else { | 
 | 3212 |       __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); | 
 | 3213 |     } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3214 |   } else { | 
 | 3215 |     // Write the value to the temporary location on the stack and load to FP stack. | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3216 |     if (!is_wide) { | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3217 |       Location stack_temp = Location::StackSlot(temp_offset); | 
 | 3218 |       codegen_->Move32(stack_temp, source); | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3219 |       if (is_fp) { | 
 | 3220 |         __ flds(Address(ESP, temp_offset)); | 
 | 3221 |       } else { | 
 | 3222 |         __ filds(Address(ESP, temp_offset)); | 
 | 3223 |       } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3224 |     } else { | 
 | 3225 |       Location stack_temp = Location::DoubleStackSlot(temp_offset); | 
 | 3226 |       codegen_->Move64(stack_temp, source); | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3227 |       if (is_fp) { | 
 | 3228 |         __ fldl(Address(ESP, temp_offset)); | 
 | 3229 |       } else { | 
 | 3230 |         __ fildl(Address(ESP, temp_offset)); | 
 | 3231 |       } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3232 |     } | 
 | 3233 |   } | 
 | 3234 | } | 
 | 3235 |  | 
 | 3236 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { | 
 | 3237 |   Primitive::Type type = rem->GetResultType(); | 
 | 3238 |   bool is_float = type == Primitive::kPrimFloat; | 
 | 3239 |   size_t elem_size = Primitive::ComponentSize(type); | 
 | 3240 |   LocationSummary* locations = rem->GetLocations(); | 
 | 3241 |   Location first = locations->InAt(0); | 
 | 3242 |   Location second = locations->InAt(1); | 
 | 3243 |   Location out = locations->Out(); | 
 | 3244 |  | 
 | 3245 |   // Create stack space for 2 elements. | 
 | 3246 |   // TODO: enhance register allocator to ask for stack temporaries. | 
 | 3247 |   __ subl(ESP, Immediate(2 * elem_size)); | 
 | 3248 |  | 
 | 3249 |   // Load the values to the FP stack in reverse order, using temporaries if needed. | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3250 |   const bool is_wide = !is_float; | 
 | 3251 |   PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); | 
 | 3252 |   PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3253 |  | 
 | 3254 |   // Loop doing FPREM until we stabilize. | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3255 |   NearLabel retry; | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3256 |   __ Bind(&retry); | 
 | 3257 |   __ fprem(); | 
 | 3258 |  | 
 | 3259 |   // Move FP status to AX. | 
 | 3260 |   __ fstsw(); | 
 | 3261 |  | 
 | 3262 |   // And see if the argument reduction is complete. This is signaled by the | 
 | 3263 |   // C2 FPU flag bit set to 0. | 
 | 3264 |   __ andl(EAX, Immediate(kC2ConditionMask)); | 
 | 3265 |   __ j(kNotEqual, &retry); | 
 | 3266 |  | 
 | 3267 |   // We have settled on the final value. Retrieve it into an XMM register. | 
 | 3268 |   // Store FP top of stack to real stack. | 
 | 3269 |   if (is_float) { | 
 | 3270 |     __ fsts(Address(ESP, 0)); | 
 | 3271 |   } else { | 
 | 3272 |     __ fstl(Address(ESP, 0)); | 
 | 3273 |   } | 
 | 3274 |  | 
 | 3275 |   // Pop the 2 items from the FP stack. | 
 | 3276 |   __ fucompp(); | 
 | 3277 |  | 
 | 3278 |   // Load the value from the stack into an XMM register. | 
 | 3279 |   DCHECK(out.IsFpuRegister()) << out; | 
 | 3280 |   if (is_float) { | 
 | 3281 |     __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); | 
 | 3282 |   } else { | 
 | 3283 |     __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); | 
 | 3284 |   } | 
 | 3285 |  | 
 | 3286 |   // And remove the temporary stack space we allocated. | 
 | 3287 |   __ addl(ESP, Immediate(2 * elem_size)); | 
 | 3288 | } | 
 | 3289 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3290 |  | 
 | 3291 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { | 
 | 3292 |   DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
 | 3293 |  | 
 | 3294 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 3295 |   DCHECK(locations->InAt(1).IsConstant()); | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3296 |   DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3297 |  | 
 | 3298 |   Register out_register = locations->Out().AsRegister<Register>(); | 
 | 3299 |   Register input_register = locations->InAt(0).AsRegister<Register>(); | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3300 |   int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3301 |  | 
 | 3302 |   DCHECK(imm == 1 || imm == -1); | 
 | 3303 |  | 
 | 3304 |   if (instruction->IsRem()) { | 
 | 3305 |     __ xorl(out_register, out_register); | 
 | 3306 |   } else { | 
 | 3307 |     __ movl(out_register, input_register); | 
 | 3308 |     if (imm == -1) { | 
 | 3309 |       __ negl(out_register); | 
 | 3310 |     } | 
 | 3311 |   } | 
 | 3312 | } | 
 | 3313 |  | 
 | 3314 |  | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3315 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3316 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 3317 |  | 
 | 3318 |   Register out_register = locations->Out().AsRegister<Register>(); | 
 | 3319 |   Register input_register = locations->InAt(0).AsRegister<Register>(); | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3320 |   int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); | 
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3321 |   DCHECK(IsPowerOfTwo(AbsOrMin(imm))); | 
 | 3322 |   uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3323 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3324 |   Register num = locations->GetTemp(0).AsRegister<Register>(); | 
 | 3325 |  | 
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3326 |   __ leal(num, Address(input_register, abs_imm - 1)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3327 |   __ testl(input_register, input_register); | 
 | 3328 |   __ cmovl(kGreaterEqual, num, input_register); | 
 | 3329 |   int shift = CTZ(imm); | 
 | 3330 |   __ sarl(num, Immediate(shift)); | 
 | 3331 |  | 
 | 3332 |   if (imm < 0) { | 
 | 3333 |     __ negl(num); | 
 | 3334 |   } | 
 | 3335 |  | 
 | 3336 |   __ movl(out_register, num); | 
 | 3337 | } | 
 | 3338 |  | 
 | 3339 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { | 
 | 3340 |   DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
 | 3341 |  | 
 | 3342 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 3343 |   int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); | 
 | 3344 |  | 
 | 3345 |   Register eax = locations->InAt(0).AsRegister<Register>(); | 
 | 3346 |   Register out = locations->Out().AsRegister<Register>(); | 
 | 3347 |   Register num; | 
 | 3348 |   Register edx; | 
 | 3349 |  | 
 | 3350 |   if (instruction->IsDiv()) { | 
 | 3351 |     edx = locations->GetTemp(0).AsRegister<Register>(); | 
 | 3352 |     num = locations->GetTemp(1).AsRegister<Register>(); | 
 | 3353 |   } else { | 
 | 3354 |     edx = locations->Out().AsRegister<Register>(); | 
 | 3355 |     num = locations->GetTemp(0).AsRegister<Register>(); | 
 | 3356 |   } | 
 | 3357 |  | 
 | 3358 |   DCHECK_EQ(EAX, eax); | 
 | 3359 |   DCHECK_EQ(EDX, edx); | 
 | 3360 |   if (instruction->IsDiv()) { | 
 | 3361 |     DCHECK_EQ(EAX, out); | 
 | 3362 |   } else { | 
 | 3363 |     DCHECK_EQ(EDX, out); | 
 | 3364 |   } | 
 | 3365 |  | 
 | 3366 |   int64_t magic; | 
 | 3367 |   int shift; | 
 | 3368 |   CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); | 
 | 3369 |  | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3370 |   NearLabel ndiv; | 
 | 3371 |   NearLabel end; | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3372 |   // If numerator is 0, the result is 0, no computation needed. | 
 | 3373 |   __ testl(eax, eax); | 
 | 3374 |   __ j(kNotEqual, &ndiv); | 
 | 3375 |  | 
 | 3376 |   __ xorl(out, out); | 
 | 3377 |   __ jmp(&end); | 
 | 3378 |  | 
 | 3379 |   __ Bind(&ndiv); | 
 | 3380 |  | 
 | 3381 |   // Save the numerator. | 
 | 3382 |   __ movl(num, eax); | 
 | 3383 |  | 
 | 3384 |   // EAX = magic | 
 | 3385 |   __ movl(eax, Immediate(magic)); | 
 | 3386 |  | 
 | 3387 |   // EDX:EAX = magic * numerator | 
 | 3388 |   __ imull(num); | 
 | 3389 |  | 
 | 3390 |   if (imm > 0 && magic < 0) { | 
 | 3391 |     // EDX += num | 
 | 3392 |     __ addl(edx, num); | 
 | 3393 |   } else if (imm < 0 && magic > 0) { | 
 | 3394 |     __ subl(edx, num); | 
 | 3395 |   } | 
 | 3396 |  | 
 | 3397 |   // Shift if needed. | 
 | 3398 |   if (shift != 0) { | 
 | 3399 |     __ sarl(edx, Immediate(shift)); | 
 | 3400 |   } | 
 | 3401 |  | 
 | 3402 |   // EDX += 1 if EDX < 0 | 
 | 3403 |   __ movl(eax, edx); | 
 | 3404 |   __ shrl(edx, Immediate(31)); | 
 | 3405 |   __ addl(edx, eax); | 
 | 3406 |  | 
 | 3407 |   if (instruction->IsRem()) { | 
 | 3408 |     __ movl(eax, num); | 
 | 3409 |     __ imull(edx, Immediate(imm)); | 
 | 3410 |     __ subl(eax, edx); | 
 | 3411 |     __ movl(edx, eax); | 
 | 3412 |   } else { | 
 | 3413 |     __ movl(eax, edx); | 
 | 3414 |   } | 
 | 3415 |   __ Bind(&end); | 
 | 3416 | } | 
 | 3417 |  | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3418 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { | 
 | 3419 |   DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
 | 3420 |  | 
 | 3421 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 3422 |   Location out = locations->Out(); | 
 | 3423 |   Location first = locations->InAt(0); | 
 | 3424 |   Location second = locations->InAt(1); | 
 | 3425 |   bool is_div = instruction->IsDiv(); | 
 | 3426 |  | 
 | 3427 |   switch (instruction->GetResultType()) { | 
 | 3428 |     case Primitive::kPrimInt: { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3429 |       DCHECK_EQ(EAX, first.AsRegister<Register>()); | 
 | 3430 |       DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3431 |  | 
| Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3432 |       if (second.IsConstant()) { | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3433 |         int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3434 |  | 
 | 3435 |         if (imm == 0) { | 
 | 3436 |           // Do not generate anything for 0. DivZeroCheck would forbid any generated code. | 
 | 3437 |         } else if (imm == 1 || imm == -1) { | 
 | 3438 |           DivRemOneOrMinusOne(instruction); | 
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3439 |         } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3440 |           DivByPowerOfTwo(instruction->AsDiv()); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3441 |         } else { | 
 | 3442 |           DCHECK(imm <= -2 || imm >= 2); | 
 | 3443 |           GenerateDivRemWithAnyConstant(instruction); | 
 | 3444 |         } | 
 | 3445 |       } else { | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3446 |         SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( | 
 | 3447 |             instruction, out.AsRegister<Register>(), is_div); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3448 |         codegen_->AddSlowPath(slow_path); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3449 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3450 |         Register second_reg = second.AsRegister<Register>(); | 
 | 3451 |         // 0x80000000/-1 triggers an arithmetic exception! | 
 | 3452 |         // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so | 
 | 3453 |         // it's safe to just use negl instead of more complex comparisons. | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3454 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3455 |         __ cmpl(second_reg, Immediate(-1)); | 
 | 3456 |         __ j(kEqual, slow_path->GetEntryLabel()); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3457 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3458 |         // edx:eax <- sign-extended of eax | 
 | 3459 |         __ cdq(); | 
 | 3460 |         // eax = quotient, edx = remainder | 
 | 3461 |         __ idivl(second_reg); | 
 | 3462 |         __ Bind(slow_path->GetExitLabel()); | 
 | 3463 |       } | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3464 |       break; | 
 | 3465 |     } | 
 | 3466 |  | 
 | 3467 |     case Primitive::kPrimLong: { | 
 | 3468 |       InvokeRuntimeCallingConvention calling_convention; | 
 | 3469 |       DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); | 
 | 3470 |       DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); | 
 | 3471 |       DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); | 
 | 3472 |       DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); | 
 | 3473 |       DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); | 
 | 3474 |       DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); | 
 | 3475 |  | 
 | 3476 |       if (is_div) { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3477 |         codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), | 
 | 3478 |                                 instruction, | 
 | 3479 |                                 instruction->GetDexPc(), | 
 | 3480 |                                 nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3481 |         CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3482 |       } else { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3483 |         codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), | 
 | 3484 |                                 instruction, | 
 | 3485 |                                 instruction->GetDexPc(), | 
 | 3486 |                                 nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3487 |         CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3488 |       } | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3489 |       break; | 
 | 3490 |     } | 
 | 3491 |  | 
 | 3492 |     default: | 
 | 3493 |       LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); | 
 | 3494 |   } | 
 | 3495 | } | 
 | 3496 |  | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3497 | void LocationsBuilderX86::VisitDiv(HDiv* div) { | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3498 |   LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3499 |       ? LocationSummary::kCall | 
 | 3500 |       : LocationSummary::kNoCall; | 
 | 3501 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); | 
 | 3502 |  | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3503 |   switch (div->GetResultType()) { | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3504 |     case Primitive::kPrimInt: { | 
 | 3505 |       locations->SetInAt(0, Location::RegisterLocation(EAX)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3506 |       locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3507 |       locations->SetOut(Location::SameAsFirstInput()); | 
 | 3508 |       // Intel uses edx:eax as the dividend. | 
 | 3509 |       locations->AddTemp(Location::RegisterLocation(EDX)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3510 |       // We need to save the numerator while we tweak eax and edx. As we are using imul in a way | 
 | 3511 |       // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as | 
 | 3512 |       // output and request another temp. | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3513 |       if (div->InputAt(1)->IsIntConstant()) { | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3514 |         locations->AddTemp(Location::RequiresRegister()); | 
 | 3515 |       } | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3516 |       break; | 
 | 3517 |     } | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3518 |     case Primitive::kPrimLong: { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3519 |       InvokeRuntimeCallingConvention calling_convention; | 
 | 3520 |       locations->SetInAt(0, Location::RegisterPairLocation( | 
 | 3521 |           calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); | 
 | 3522 |       locations->SetInAt(1, Location::RegisterPairLocation( | 
 | 3523 |           calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); | 
 | 3524 |       // Runtime helper puts the result in EAX, EDX. | 
 | 3525 |       locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3526 |       break; | 
 | 3527 |     } | 
 | 3528 |     case Primitive::kPrimFloat: | 
 | 3529 |     case Primitive::kPrimDouble: { | 
 | 3530 |       locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3531 |       if (div->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 3532 |         DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); | 
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3533 |       } else if (div->InputAt(1)->IsConstant()) { | 
 | 3534 |         locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3535 |       } else { | 
 | 3536 |         locations->SetInAt(1, Location::Any()); | 
 | 3537 |       } | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3538 |       locations->SetOut(Location::SameAsFirstInput()); | 
 | 3539 |       break; | 
 | 3540 |     } | 
 | 3541 |  | 
 | 3542 |     default: | 
 | 3543 |       LOG(FATAL) << "Unexpected div type " << div->GetResultType(); | 
 | 3544 |   } | 
 | 3545 | } | 
 | 3546 |  | 
 | 3547 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { | 
 | 3548 |   LocationSummary* locations = div->GetLocations(); | 
 | 3549 |   Location first = locations->InAt(0); | 
 | 3550 |   Location second = locations->InAt(1); | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3551 |  | 
 | 3552 |   switch (div->GetResultType()) { | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3553 |     case Primitive::kPrimInt: | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3554 |     case Primitive::kPrimLong: { | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3555 |       GenerateDivRemIntegral(div); | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3556 |       break; | 
 | 3557 |     } | 
 | 3558 |  | 
 | 3559 |     case Primitive::kPrimFloat: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3560 |       if (second.IsFpuRegister()) { | 
 | 3561 |         __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
 | 3562 |       } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 3563 |         HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3564 |         DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3565 |         __ divss(first.AsFpuRegister<XmmRegister>(), | 
 | 3566 |                  codegen_->LiteralFloatAddress( | 
 | 3567 |                    const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
 | 3568 |                    const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 3569 |       } else { | 
 | 3570 |         DCHECK(second.IsStackSlot()); | 
 | 3571 |         __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
 | 3572 |       } | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3573 |       break; | 
 | 3574 |     } | 
 | 3575 |  | 
 | 3576 |     case Primitive::kPrimDouble: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3577 |       if (second.IsFpuRegister()) { | 
 | 3578 |         __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
 | 3579 |       } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 3580 |         HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3581 |         DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3582 |         __ divsd(first.AsFpuRegister<XmmRegister>(), | 
 | 3583 |                  codegen_->LiteralDoubleAddress( | 
 | 3584 |                    const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
 | 3585 |                    const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
 | 3586 |       } else { | 
 | 3587 |         DCHECK(second.IsDoubleStackSlot()); | 
 | 3588 |         __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
 | 3589 |       } | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3590 |       break; | 
 | 3591 |     } | 
 | 3592 |  | 
 | 3593 |     default: | 
 | 3594 |       LOG(FATAL) << "Unexpected div type " << div->GetResultType(); | 
 | 3595 |   } | 
 | 3596 | } | 
 | 3597 |  | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3598 | void LocationsBuilderX86::VisitRem(HRem* rem) { | 
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3599 |   Primitive::Type type = rem->GetResultType(); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3600 |  | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3601 |   LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) | 
 | 3602 |       ? LocationSummary::kCall | 
 | 3603 |       : LocationSummary::kNoCall; | 
 | 3604 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3605 |  | 
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3606 |   switch (type) { | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3607 |     case Primitive::kPrimInt: { | 
 | 3608 |       locations->SetInAt(0, Location::RegisterLocation(EAX)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3609 |       locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3610 |       locations->SetOut(Location::RegisterLocation(EDX)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3611 |       // We need to save the numerator while we tweak eax and edx. As we are using imul in a way | 
 | 3612 |       // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as | 
 | 3613 |       // output and request another temp. | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3614 |       if (rem->InputAt(1)->IsIntConstant()) { | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3615 |         locations->AddTemp(Location::RequiresRegister()); | 
 | 3616 |       } | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3617 |       break; | 
 | 3618 |     } | 
 | 3619 |     case Primitive::kPrimLong: { | 
 | 3620 |       InvokeRuntimeCallingConvention calling_convention; | 
 | 3621 |       locations->SetInAt(0, Location::RegisterPairLocation( | 
 | 3622 |           calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); | 
 | 3623 |       locations->SetInAt(1, Location::RegisterPairLocation( | 
 | 3624 |           calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); | 
 | 3625 |       // Runtime helper puts the result in EAX, EDX. | 
 | 3626 |       locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); | 
 | 3627 |       break; | 
 | 3628 |     } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3629 |     case Primitive::kPrimDouble: | 
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3630 |     case Primitive::kPrimFloat: { | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3631 |       locations->SetInAt(0, Location::Any()); | 
 | 3632 |       locations->SetInAt(1, Location::Any()); | 
 | 3633 |       locations->SetOut(Location::RequiresFpuRegister()); | 
 | 3634 |       locations->AddTemp(Location::RegisterLocation(EAX)); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3635 |       break; | 
 | 3636 |     } | 
 | 3637 |  | 
 | 3638 |     default: | 
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3639 |       LOG(FATAL) << "Unexpected rem type " << type; | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3640 |   } | 
 | 3641 | } | 
 | 3642 |  | 
 | 3643 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { | 
 | 3644 |   Primitive::Type type = rem->GetResultType(); | 
 | 3645 |   switch (type) { | 
 | 3646 |     case Primitive::kPrimInt: | 
 | 3647 |     case Primitive::kPrimLong: { | 
 | 3648 |       GenerateDivRemIntegral(rem); | 
 | 3649 |       break; | 
 | 3650 |     } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3651 |     case Primitive::kPrimFloat: | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3652 |     case Primitive::kPrimDouble: { | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3653 |       GenerateRemFP(rem); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3654 |       break; | 
 | 3655 |     } | 
 | 3656 |     default: | 
 | 3657 |       LOG(FATAL) << "Unexpected rem type " << type; | 
 | 3658 |   } | 
 | 3659 | } | 
 | 3660 |  | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3661 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3662 |   LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
 | 3663 |       ? LocationSummary::kCallOnSlowPath | 
 | 3664 |       : LocationSummary::kNoCall; | 
 | 3665 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3666 |   switch (instruction->GetType()) { | 
| Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3667 |     case Primitive::kPrimBoolean: | 
| Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3668 |     case Primitive::kPrimByte: | 
 | 3669 |     case Primitive::kPrimChar: | 
 | 3670 |     case Primitive::kPrimShort: | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3671 |     case Primitive::kPrimInt: { | 
 | 3672 |       locations->SetInAt(0, Location::Any()); | 
 | 3673 |       break; | 
 | 3674 |     } | 
 | 3675 |     case Primitive::kPrimLong: { | 
 | 3676 |       locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); | 
 | 3677 |       if (!instruction->IsConstant()) { | 
 | 3678 |         locations->AddTemp(Location::RequiresRegister()); | 
 | 3679 |       } | 
 | 3680 |       break; | 
 | 3681 |     } | 
 | 3682 |     default: | 
 | 3683 |       LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); | 
 | 3684 |   } | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3685 |   if (instruction->HasUses()) { | 
 | 3686 |     locations->SetOut(Location::SameAsFirstInput()); | 
 | 3687 |   } | 
 | 3688 | } | 
 | 3689 |  | 
 | 3690 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3691 |   SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3692 |   codegen_->AddSlowPath(slow_path); | 
 | 3693 |  | 
 | 3694 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 3695 |   Location value = locations->InAt(0); | 
 | 3696 |  | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3697 |   switch (instruction->GetType()) { | 
| Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3698 |     case Primitive::kPrimBoolean: | 
| Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3699 |     case Primitive::kPrimByte: | 
 | 3700 |     case Primitive::kPrimChar: | 
 | 3701 |     case Primitive::kPrimShort: | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3702 |     case Primitive::kPrimInt: { | 
 | 3703 |       if (value.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3704 |         __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3705 |         __ j(kEqual, slow_path->GetEntryLabel()); | 
 | 3706 |       } else if (value.IsStackSlot()) { | 
 | 3707 |         __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); | 
 | 3708 |         __ j(kEqual, slow_path->GetEntryLabel()); | 
 | 3709 |       } else { | 
 | 3710 |         DCHECK(value.IsConstant()) << value; | 
 | 3711 |         if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { | 
 | 3712 |         __ jmp(slow_path->GetEntryLabel()); | 
 | 3713 |         } | 
 | 3714 |       } | 
 | 3715 |       break; | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3716 |     } | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3717 |     case Primitive::kPrimLong: { | 
 | 3718 |       if (value.IsRegisterPair()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3719 |         Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3720 |         __ movl(temp, value.AsRegisterPairLow<Register>()); | 
 | 3721 |         __ orl(temp, value.AsRegisterPairHigh<Register>()); | 
 | 3722 |         __ j(kEqual, slow_path->GetEntryLabel()); | 
 | 3723 |       } else { | 
 | 3724 |         DCHECK(value.IsConstant()) << value; | 
 | 3725 |         if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { | 
 | 3726 |           __ jmp(slow_path->GetEntryLabel()); | 
 | 3727 |         } | 
 | 3728 |       } | 
 | 3729 |       break; | 
 | 3730 |     } | 
 | 3731 |     default: | 
 | 3732 |       LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3733 |   } | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3734 | } | 
 | 3735 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3736 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { | 
 | 3737 |   DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); | 
 | 3738 |  | 
 | 3739 |   LocationSummary* locations = | 
 | 3740 |       new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); | 
 | 3741 |  | 
 | 3742 |   switch (op->GetResultType()) { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3743 |     case Primitive::kPrimInt: | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3744 |     case Primitive::kPrimLong: { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3745 |       // Can't have Location::Any() and output SameAsFirstInput() | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3746 |       locations->SetInAt(0, Location::RequiresRegister()); | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3747 |       // The shift count needs to be in CL or a constant. | 
 | 3748 |       locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3749 |       locations->SetOut(Location::SameAsFirstInput()); | 
 | 3750 |       break; | 
 | 3751 |     } | 
 | 3752 |     default: | 
 | 3753 |       LOG(FATAL) << "Unexpected op type " << op->GetResultType(); | 
 | 3754 |   } | 
 | 3755 | } | 
 | 3756 |  | 
 | 3757 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { | 
 | 3758 |   DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); | 
 | 3759 |  | 
 | 3760 |   LocationSummary* locations = op->GetLocations(); | 
 | 3761 |   Location first = locations->InAt(0); | 
 | 3762 |   Location second = locations->InAt(1); | 
 | 3763 |   DCHECK(first.Equals(locations->Out())); | 
 | 3764 |  | 
 | 3765 |   switch (op->GetResultType()) { | 
 | 3766 |     case Primitive::kPrimInt: { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3767 |       DCHECK(first.IsRegister()); | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3768 |       Register first_reg = first.AsRegister<Register>(); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3769 |       if (second.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3770 |         Register second_reg = second.AsRegister<Register>(); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3771 |         DCHECK_EQ(ECX, second_reg); | 
 | 3772 |         if (op->IsShl()) { | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3773 |           __ shll(first_reg, second_reg); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3774 |         } else if (op->IsShr()) { | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3775 |           __ sarl(first_reg, second_reg); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3776 |         } else { | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3777 |           __ shrl(first_reg, second_reg); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3778 |         } | 
 | 3779 |       } else { | 
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3780 |         int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3781 |         if (shift == 0) { | 
 | 3782 |           return; | 
 | 3783 |         } | 
 | 3784 |         Immediate imm(shift); | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3785 |         if (op->IsShl()) { | 
 | 3786 |           __ shll(first_reg, imm); | 
 | 3787 |         } else if (op->IsShr()) { | 
 | 3788 |           __ sarl(first_reg, imm); | 
 | 3789 |         } else { | 
 | 3790 |           __ shrl(first_reg, imm); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3791 |         } | 
 | 3792 |       } | 
 | 3793 |       break; | 
 | 3794 |     } | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3795 |     case Primitive::kPrimLong: { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3796 |       if (second.IsRegister()) { | 
 | 3797 |         Register second_reg = second.AsRegister<Register>(); | 
 | 3798 |         DCHECK_EQ(ECX, second_reg); | 
 | 3799 |         if (op->IsShl()) { | 
 | 3800 |           GenerateShlLong(first, second_reg); | 
 | 3801 |         } else if (op->IsShr()) { | 
 | 3802 |           GenerateShrLong(first, second_reg); | 
 | 3803 |         } else { | 
 | 3804 |           GenerateUShrLong(first, second_reg); | 
 | 3805 |         } | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3806 |       } else { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3807 |         // Shift by a constant. | 
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3808 |         int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3809 |         // Nothing to do if the shift is 0, as the input is already the output. | 
 | 3810 |         if (shift != 0) { | 
 | 3811 |           if (op->IsShl()) { | 
 | 3812 |             GenerateShlLong(first, shift); | 
 | 3813 |           } else if (op->IsShr()) { | 
 | 3814 |             GenerateShrLong(first, shift); | 
 | 3815 |           } else { | 
 | 3816 |             GenerateUShrLong(first, shift); | 
 | 3817 |           } | 
 | 3818 |         } | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3819 |       } | 
 | 3820 |       break; | 
 | 3821 |     } | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3822 |     default: | 
 | 3823 |       LOG(FATAL) << "Unexpected op type " << op->GetResultType(); | 
 | 3824 |   } | 
 | 3825 | } | 
 | 3826 |  | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3827 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { | 
 | 3828 |   Register low = loc.AsRegisterPairLow<Register>(); | 
 | 3829 |   Register high = loc.AsRegisterPairHigh<Register>(); | 
| Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3830 |   if (shift == 1) { | 
 | 3831 |     // This is just an addition. | 
 | 3832 |     __ addl(low, low); | 
 | 3833 |     __ adcl(high, high); | 
 | 3834 |   } else if (shift == 32) { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3835 |     // Shift by 32 is easy. High gets low, and low gets 0. | 
 | 3836 |     codegen_->EmitParallelMoves( | 
 | 3837 |         loc.ToLow(), | 
 | 3838 |         loc.ToHigh(), | 
 | 3839 |         Primitive::kPrimInt, | 
 | 3840 |         Location::ConstantLocation(GetGraph()->GetIntConstant(0)), | 
 | 3841 |         loc.ToLow(), | 
 | 3842 |         Primitive::kPrimInt); | 
 | 3843 |   } else if (shift > 32) { | 
 | 3844 |     // Low part becomes 0.  High part is low part << (shift-32). | 
 | 3845 |     __ movl(high, low); | 
 | 3846 |     __ shll(high, Immediate(shift - 32)); | 
 | 3847 |     __ xorl(low, low); | 
 | 3848 |   } else { | 
 | 3849 |     // Between 1 and 31. | 
 | 3850 |     __ shld(high, low, Immediate(shift)); | 
 | 3851 |     __ shll(low, Immediate(shift)); | 
 | 3852 |   } | 
 | 3853 | } | 
 | 3854 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3855 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3856 |   NearLabel done; | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3857 |   __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); | 
 | 3858 |   __ shll(loc.AsRegisterPairLow<Register>(), shifter); | 
 | 3859 |   __ testl(shifter, Immediate(32)); | 
 | 3860 |   __ j(kEqual, &done); | 
 | 3861 |   __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); | 
 | 3862 |   __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); | 
 | 3863 |   __ Bind(&done); | 
 | 3864 | } | 
 | 3865 |  | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3866 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { | 
 | 3867 |   Register low = loc.AsRegisterPairLow<Register>(); | 
 | 3868 |   Register high = loc.AsRegisterPairHigh<Register>(); | 
 | 3869 |   if (shift == 32) { | 
 | 3870 |     // Need to copy the sign. | 
 | 3871 |     DCHECK_NE(low, high); | 
 | 3872 |     __ movl(low, high); | 
 | 3873 |     __ sarl(high, Immediate(31)); | 
 | 3874 |   } else if (shift > 32) { | 
 | 3875 |     DCHECK_NE(low, high); | 
 | 3876 |     // High part becomes sign. Low part is shifted by shift - 32. | 
 | 3877 |     __ movl(low, high); | 
 | 3878 |     __ sarl(high, Immediate(31)); | 
 | 3879 |     __ sarl(low, Immediate(shift - 32)); | 
 | 3880 |   } else { | 
 | 3881 |     // Between 1 and 31. | 
 | 3882 |     __ shrd(low, high, Immediate(shift)); | 
 | 3883 |     __ sarl(high, Immediate(shift)); | 
 | 3884 |   } | 
 | 3885 | } | 
 | 3886 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3887 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3888 |   NearLabel done; | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3889 |   __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); | 
 | 3890 |   __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); | 
 | 3891 |   __ testl(shifter, Immediate(32)); | 
 | 3892 |   __ j(kEqual, &done); | 
 | 3893 |   __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); | 
 | 3894 |   __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); | 
 | 3895 |   __ Bind(&done); | 
 | 3896 | } | 
 | 3897 |  | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3898 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { | 
 | 3899 |   Register low = loc.AsRegisterPairLow<Register>(); | 
 | 3900 |   Register high = loc.AsRegisterPairHigh<Register>(); | 
 | 3901 |   if (shift == 32) { | 
 | 3902 |     // Shift by 32 is easy. Low gets high, and high gets 0. | 
 | 3903 |     codegen_->EmitParallelMoves( | 
 | 3904 |         loc.ToHigh(), | 
 | 3905 |         loc.ToLow(), | 
 | 3906 |         Primitive::kPrimInt, | 
 | 3907 |         Location::ConstantLocation(GetGraph()->GetIntConstant(0)), | 
 | 3908 |         loc.ToHigh(), | 
 | 3909 |         Primitive::kPrimInt); | 
 | 3910 |   } else if (shift > 32) { | 
 | 3911 |     // Low part is high >> (shift - 32). High part becomes 0. | 
 | 3912 |     __ movl(low, high); | 
 | 3913 |     __ shrl(low, Immediate(shift - 32)); | 
 | 3914 |     __ xorl(high, high); | 
 | 3915 |   } else { | 
 | 3916 |     // Between 1 and 31. | 
 | 3917 |     __ shrd(low, high, Immediate(shift)); | 
 | 3918 |     __ shrl(high, Immediate(shift)); | 
 | 3919 |   } | 
 | 3920 | } | 
 | 3921 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3922 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3923 |   NearLabel done; | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3924 |   __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); | 
 | 3925 |   __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); | 
 | 3926 |   __ testl(shifter, Immediate(32)); | 
 | 3927 |   __ j(kEqual, &done); | 
 | 3928 |   __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); | 
 | 3929 |   __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); | 
 | 3930 |   __ Bind(&done); | 
 | 3931 | } | 
 | 3932 |  | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3933 | void LocationsBuilderX86::VisitRor(HRor* ror) { | 
 | 3934 |   LocationSummary* locations = | 
 | 3935 |       new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); | 
 | 3936 |  | 
 | 3937 |   switch (ror->GetResultType()) { | 
 | 3938 |     case Primitive::kPrimLong: | 
 | 3939 |       // Add the temporary needed. | 
 | 3940 |       locations->AddTemp(Location::RequiresRegister()); | 
 | 3941 |       FALLTHROUGH_INTENDED; | 
 | 3942 |     case Primitive::kPrimInt: | 
 | 3943 |       locations->SetInAt(0, Location::RequiresRegister()); | 
 | 3944 |       // The shift count needs to be in CL (unless it is a constant). | 
 | 3945 |       locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); | 
 | 3946 |       locations->SetOut(Location::SameAsFirstInput()); | 
 | 3947 |       break; | 
 | 3948 |     default: | 
 | 3949 |       LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); | 
 | 3950 |       UNREACHABLE(); | 
 | 3951 |   } | 
 | 3952 | } | 
 | 3953 |  | 
 | 3954 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { | 
 | 3955 |   LocationSummary* locations = ror->GetLocations(); | 
 | 3956 |   Location first = locations->InAt(0); | 
 | 3957 |   Location second = locations->InAt(1); | 
 | 3958 |  | 
 | 3959 |   if (ror->GetResultType() == Primitive::kPrimInt) { | 
 | 3960 |     Register first_reg = first.AsRegister<Register>(); | 
 | 3961 |     if (second.IsRegister()) { | 
 | 3962 |       Register second_reg = second.AsRegister<Register>(); | 
 | 3963 |       __ rorl(first_reg, second_reg); | 
 | 3964 |     } else { | 
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3965 |       Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3966 |       __ rorl(first_reg, imm); | 
 | 3967 |     } | 
 | 3968 |     return; | 
 | 3969 |   } | 
 | 3970 |  | 
 | 3971 |   DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); | 
 | 3972 |   Register first_reg_lo = first.AsRegisterPairLow<Register>(); | 
 | 3973 |   Register first_reg_hi = first.AsRegisterPairHigh<Register>(); | 
 | 3974 |   Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); | 
 | 3975 |   if (second.IsRegister()) { | 
 | 3976 |     Register second_reg = second.AsRegister<Register>(); | 
 | 3977 |     DCHECK_EQ(second_reg, ECX); | 
 | 3978 |     __ movl(temp_reg, first_reg_hi); | 
 | 3979 |     __ shrd(first_reg_hi, first_reg_lo, second_reg); | 
 | 3980 |     __ shrd(first_reg_lo, temp_reg, second_reg); | 
 | 3981 |     __ movl(temp_reg, first_reg_hi); | 
 | 3982 |     __ testl(second_reg, Immediate(32)); | 
 | 3983 |     __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); | 
 | 3984 |     __ cmovl(kNotEqual, first_reg_lo, temp_reg); | 
 | 3985 |   } else { | 
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3986 |     int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3987 |     if (shift_amt == 0) { | 
 | 3988 |       // Already fine. | 
 | 3989 |       return; | 
 | 3990 |     } | 
 | 3991 |     if (shift_amt == 32) { | 
 | 3992 |       // Just swap. | 
 | 3993 |       __ movl(temp_reg, first_reg_lo); | 
 | 3994 |       __ movl(first_reg_lo, first_reg_hi); | 
 | 3995 |       __ movl(first_reg_hi, temp_reg); | 
 | 3996 |       return; | 
 | 3997 |     } | 
 | 3998 |  | 
 | 3999 |     Immediate imm(shift_amt); | 
 | 4000 |     // Save the constents of the low value. | 
 | 4001 |     __ movl(temp_reg, first_reg_lo); | 
 | 4002 |  | 
 | 4003 |     // Shift right into low, feeding bits from high. | 
 | 4004 |     __ shrd(first_reg_lo, first_reg_hi, imm); | 
 | 4005 |  | 
 | 4006 |     // Shift right into high, feeding bits from the original low. | 
 | 4007 |     __ shrd(first_reg_hi, temp_reg, imm); | 
 | 4008 |  | 
 | 4009 |     // Swap if needed. | 
 | 4010 |     if (shift_amt > 32) { | 
 | 4011 |       __ movl(temp_reg, first_reg_lo); | 
 | 4012 |       __ movl(first_reg_lo, first_reg_hi); | 
 | 4013 |       __ movl(first_reg_hi, temp_reg); | 
 | 4014 |     } | 
 | 4015 |   } | 
 | 4016 | } | 
 | 4017 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4018 | void LocationsBuilderX86::VisitShl(HShl* shl) { | 
 | 4019 |   HandleShift(shl); | 
 | 4020 | } | 
 | 4021 |  | 
 | 4022 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { | 
 | 4023 |   HandleShift(shl); | 
 | 4024 | } | 
 | 4025 |  | 
 | 4026 | void LocationsBuilderX86::VisitShr(HShr* shr) { | 
 | 4027 |   HandleShift(shr); | 
 | 4028 | } | 
 | 4029 |  | 
 | 4030 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { | 
 | 4031 |   HandleShift(shr); | 
 | 4032 | } | 
 | 4033 |  | 
 | 4034 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { | 
 | 4035 |   HandleShift(ushr); | 
 | 4036 | } | 
 | 4037 |  | 
 | 4038 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { | 
 | 4039 |   HandleShift(ushr); | 
 | 4040 | } | 
 | 4041 |  | 
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4042 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4043 |   LocationSummary* locations = | 
 | 4044 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4045 |   locations->SetOut(Location::RegisterLocation(EAX)); | 
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4046 |   if (instruction->IsStringAlloc()) { | 
 | 4047 |     locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); | 
 | 4048 |   } else { | 
 | 4049 |     InvokeRuntimeCallingConvention calling_convention; | 
 | 4050 |     locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
 | 4051 |     locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
 | 4052 |   } | 
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4053 | } | 
 | 4054 |  | 
 | 4055 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4056 |   // Note: if heap poisoning is enabled, the entry point takes cares | 
 | 4057 |   // of poisoning the reference. | 
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4058 |   if (instruction->IsStringAlloc()) { | 
 | 4059 |     // String is allocated through StringFactory. Call NewEmptyString entry point. | 
 | 4060 |     Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); | 
 | 4061 |     MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); | 
 | 4062 |     __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); | 
 | 4063 |     __ call(Address(temp, code_offset.Int32Value())); | 
 | 4064 |     codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); | 
 | 4065 |   } else { | 
 | 4066 |     codegen_->InvokeRuntime(instruction->GetEntrypoint(), | 
 | 4067 |                             instruction, | 
 | 4068 |                             instruction->GetDexPc(), | 
 | 4069 |                             nullptr); | 
 | 4070 |     CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); | 
 | 4071 |     DCHECK(!codegen_->IsLeafMethod()); | 
 | 4072 |   } | 
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4073 | } | 
 | 4074 |  | 
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4075 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { | 
 | 4076 |   LocationSummary* locations = | 
 | 4077 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
 | 4078 |   locations->SetOut(Location::RegisterLocation(EAX)); | 
 | 4079 |   InvokeRuntimeCallingConvention calling_convention; | 
 | 4080 |   locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
| Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4081 |   locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
| Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4082 |   locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); | 
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4083 | } | 
 | 4084 |  | 
 | 4085 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { | 
 | 4086 |   InvokeRuntimeCallingConvention calling_convention; | 
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4087 |   __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4088 |   // Note: if heap poisoning is enabled, the entry point takes cares | 
 | 4089 |   // of poisoning the reference. | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4090 |   codegen_->InvokeRuntime(instruction->GetEntrypoint(), | 
 | 4091 |                           instruction, | 
 | 4092 |                           instruction->GetDexPc(), | 
 | 4093 |                           nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4094 |   CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); | 
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4095 |   DCHECK(!codegen_->IsLeafMethod()); | 
 | 4096 | } | 
 | 4097 |  | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4098 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4099 |   LocationSummary* locations = | 
 | 4100 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4101 |   Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); | 
 | 4102 |   if (location.IsStackSlot()) { | 
 | 4103 |     location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
 | 4104 |   } else if (location.IsDoubleStackSlot()) { | 
 | 4105 |     location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4106 |   } | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4107 |   locations->SetOut(location); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4108 | } | 
 | 4109 |  | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4110 | void InstructionCodeGeneratorX86::VisitParameterValue( | 
 | 4111 |     HParameterValue* instruction ATTRIBUTE_UNUSED) { | 
 | 4112 | } | 
 | 4113 |  | 
 | 4114 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { | 
 | 4115 |   LocationSummary* locations = | 
 | 4116 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
 | 4117 |   locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); | 
 | 4118 | } | 
 | 4119 |  | 
 | 4120 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4121 | } | 
 | 4122 |  | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4123 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { | 
 | 4124 |   LocationSummary* locations = | 
 | 4125 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
 | 4126 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 4127 |   locations->SetOut(Location::RequiresRegister()); | 
 | 4128 | } | 
 | 4129 |  | 
 | 4130 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { | 
 | 4131 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 4132 |   uint32_t method_offset = 0; | 
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4133 |   if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4134 |     method_offset = mirror::Class::EmbeddedVTableEntryOffset( | 
 | 4135 |         instruction->GetIndex(), kX86PointerSize).SizeValue(); | 
 | 4136 |   } else { | 
 | 4137 |     method_offset = mirror::Class::EmbeddedImTableEntryOffset( | 
 | 4138 |         instruction->GetIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); | 
 | 4139 |   } | 
 | 4140 |   __ movl(locations->Out().AsRegister<Register>(), | 
 | 4141 |           Address(locations->InAt(0).AsRegister<Register>(), method_offset)); | 
 | 4142 | } | 
 | 4143 |  | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4144 | void LocationsBuilderX86::VisitNot(HNot* not_) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4145 |   LocationSummary* locations = | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4146 |       new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4147 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 4148 |   locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4149 | } | 
 | 4150 |  | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4151 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { | 
 | 4152 |   LocationSummary* locations = not_->GetLocations(); | 
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4153 |   Location in = locations->InAt(0); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4154 |   Location out = locations->Out(); | 
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4155 |   DCHECK(in.Equals(out)); | 
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4156 |   switch (not_->GetResultType()) { | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4157 |     case Primitive::kPrimInt: | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4158 |       __ notl(out.AsRegister<Register>()); | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4159 |       break; | 
 | 4160 |  | 
 | 4161 |     case Primitive::kPrimLong: | 
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4162 |       __ notl(out.AsRegisterPairLow<Register>()); | 
 | 4163 |       __ notl(out.AsRegisterPairHigh<Register>()); | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4164 |       break; | 
 | 4165 |  | 
 | 4166 |     default: | 
 | 4167 |       LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); | 
 | 4168 |   } | 
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4169 | } | 
 | 4170 |  | 
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4171 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { | 
 | 4172 |   LocationSummary* locations = | 
 | 4173 |       new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); | 
 | 4174 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 4175 |   locations->SetOut(Location::SameAsFirstInput()); | 
 | 4176 | } | 
 | 4177 |  | 
 | 4178 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { | 
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4179 |   LocationSummary* locations = bool_not->GetLocations(); | 
 | 4180 |   Location in = locations->InAt(0); | 
 | 4181 |   Location out = locations->Out(); | 
 | 4182 |   DCHECK(in.Equals(out)); | 
 | 4183 |   __ xorl(out.AsRegister<Register>(), Immediate(1)); | 
 | 4184 | } | 
 | 4185 |  | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4186 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4187 |   LocationSummary* locations = | 
 | 4188 |       new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4189 |   switch (compare->InputAt(0)->GetType()) { | 
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4190 |     case Primitive::kPrimBoolean: | 
 | 4191 |     case Primitive::kPrimByte: | 
 | 4192 |     case Primitive::kPrimShort: | 
 | 4193 |     case Primitive::kPrimChar: | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4194 |     case Primitive::kPrimInt: | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4195 |     case Primitive::kPrimLong: { | 
 | 4196 |       locations->SetInAt(0, Location::RequiresRegister()); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4197 |       locations->SetInAt(1, Location::Any()); | 
 | 4198 |       locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
 | 4199 |       break; | 
 | 4200 |     } | 
 | 4201 |     case Primitive::kPrimFloat: | 
 | 4202 |     case Primitive::kPrimDouble: { | 
 | 4203 |       locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4204 |       if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { | 
 | 4205 |         DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); | 
 | 4206 |       } else if (compare->InputAt(1)->IsConstant()) { | 
 | 4207 |         locations->SetInAt(1, Location::RequiresFpuRegister()); | 
 | 4208 |       } else { | 
 | 4209 |         locations->SetInAt(1, Location::Any()); | 
 | 4210 |       } | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4211 |       locations->SetOut(Location::RequiresRegister()); | 
 | 4212 |       break; | 
 | 4213 |     } | 
 | 4214 |     default: | 
 | 4215 |       LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); | 
 | 4216 |   } | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4217 | } | 
 | 4218 |  | 
 | 4219 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4220 |   LocationSummary* locations = compare->GetLocations(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4221 |   Register out = locations->Out().AsRegister<Register>(); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4222 |   Location left = locations->InAt(0); | 
 | 4223 |   Location right = locations->InAt(1); | 
 | 4224 |  | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4225 |   NearLabel less, greater, done; | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4226 |   Condition less_cond = kLess; | 
 | 4227 |  | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4228 |   switch (compare->InputAt(0)->GetType()) { | 
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4229 |     case Primitive::kPrimBoolean: | 
 | 4230 |     case Primitive::kPrimByte: | 
 | 4231 |     case Primitive::kPrimShort: | 
 | 4232 |     case Primitive::kPrimChar: | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4233 |     case Primitive::kPrimInt: { | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 4234 |       GenerateIntCompare(left, right); | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4235 |       break; | 
 | 4236 |     } | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4237 |     case Primitive::kPrimLong: { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4238 |       Register left_low = left.AsRegisterPairLow<Register>(); | 
 | 4239 |       Register left_high = left.AsRegisterPairHigh<Register>(); | 
 | 4240 |       int32_t val_low = 0; | 
 | 4241 |       int32_t val_high = 0; | 
 | 4242 |       bool right_is_const = false; | 
 | 4243 |  | 
 | 4244 |       if (right.IsConstant()) { | 
 | 4245 |         DCHECK(right.GetConstant()->IsLongConstant()); | 
 | 4246 |         right_is_const = true; | 
 | 4247 |         int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); | 
 | 4248 |         val_low = Low32Bits(val); | 
 | 4249 |         val_high = High32Bits(val); | 
 | 4250 |       } | 
 | 4251 |  | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4252 |       if (right.IsRegisterPair()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4253 |         __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4254 |       } else if (right.IsDoubleStackSlot()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4255 |         __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4256 |       } else { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4257 |         DCHECK(right_is_const) << right; | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4258 |         codegen_->Compare32BitValue(left_high, val_high); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4259 |       } | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4260 |       __ j(kLess, &less);  // Signed compare. | 
 | 4261 |       __ j(kGreater, &greater);  // Signed compare. | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4262 |       if (right.IsRegisterPair()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4263 |         __ cmpl(left_low, right.AsRegisterPairLow<Register>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4264 |       } else if (right.IsDoubleStackSlot()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4265 |         __ cmpl(left_low, Address(ESP, right.GetStackIndex())); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4266 |       } else { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4267 |         DCHECK(right_is_const) << right; | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4268 |         codegen_->Compare32BitValue(left_low, val_low); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4269 |       } | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4270 |       less_cond = kBelow;  // for CF (unsigned). | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4271 |       break; | 
 | 4272 |     } | 
 | 4273 |     case Primitive::kPrimFloat: { | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4274 |       GenerateFPCompare(left, right, compare, false); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4275 |       __ j(kUnordered, compare->IsGtBias() ? &greater : &less); | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4276 |       less_cond = kBelow;  // for CF (floats). | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4277 |       break; | 
 | 4278 |     } | 
 | 4279 |     case Primitive::kPrimDouble: { | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4280 |       GenerateFPCompare(left, right, compare, true); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4281 |       __ j(kUnordered, compare->IsGtBias() ? &greater : &less); | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4282 |       less_cond = kBelow;  // for CF (floats). | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4283 |       break; | 
 | 4284 |     } | 
 | 4285 |     default: | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4286 |       LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4287 |   } | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4288 |  | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4289 |   __ movl(out, Immediate(0)); | 
 | 4290 |   __ j(kEqual, &done); | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4291 |   __ j(less_cond, &less); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4292 |  | 
 | 4293 |   __ Bind(&greater); | 
 | 4294 |   __ movl(out, Immediate(1)); | 
 | 4295 |   __ jmp(&done); | 
 | 4296 |  | 
 | 4297 |   __ Bind(&less); | 
 | 4298 |   __ movl(out, Immediate(-1)); | 
 | 4299 |  | 
 | 4300 |   __ Bind(&done); | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4301 | } | 
 | 4302 |  | 
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4303 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4304 |   LocationSummary* locations = | 
 | 4305 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4306 |   for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { | 
 | 4307 |     locations->SetInAt(i, Location::Any()); | 
 | 4308 |   } | 
 | 4309 |   locations->SetOut(Location::Any()); | 
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4310 | } | 
 | 4311 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4312 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4313 |   LOG(FATAL) << "Unreachable"; | 
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4314 | } | 
 | 4315 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4316 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4317 |   /* | 
 | 4318 |    * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. | 
 | 4319 |    * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. | 
 | 4320 |    * For those cases, all we need to ensure is that there is a scheduling barrier in place. | 
 | 4321 |    */ | 
 | 4322 |   switch (kind) { | 
 | 4323 |     case MemBarrierKind::kAnyAny: { | 
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4324 |       MemoryFence(); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4325 |       break; | 
 | 4326 |     } | 
 | 4327 |     case MemBarrierKind::kAnyStore: | 
 | 4328 |     case MemBarrierKind::kLoadAny: | 
 | 4329 |     case MemBarrierKind::kStoreStore: { | 
 | 4330 |       // nop | 
 | 4331 |       break; | 
 | 4332 |     } | 
 | 4333 |     default: | 
 | 4334 |       LOG(FATAL) << "Unexpected memory barrier " << kind; | 
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4335 |   } | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4336 | } | 
 | 4337 |  | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4338 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( | 
 | 4339 |       const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, | 
 | 4340 |       MethodReference target_method ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4341 |   HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; | 
 | 4342 |  | 
 | 4343 |   // We disable pc-relative load when there is an irreducible loop, as the optimization | 
 | 4344 |   // is incompatible with it. | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4345 |   // TODO: Create as many X86ComputeBaseMethodAddress instructions | 
 | 4346 |   // as needed for methods with irreducible loops. | 
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4347 |   if (GetGraph()->HasIrreducibleLoops() && | 
 | 4348 |       (dispatch_info.method_load_kind == | 
 | 4349 |           HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { | 
 | 4350 |     dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; | 
 | 4351 |   } | 
 | 4352 |   switch (dispatch_info.code_ptr_location) { | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4353 |     case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: | 
 | 4354 |     case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: | 
 | 4355 |       // For direct code, we actually prefer to call via the code pointer from ArtMethod*. | 
 | 4356 |       // (Though the direct CALL ptr16:32 is available for consideration). | 
 | 4357 |       return HInvokeStaticOrDirect::DispatchInfo { | 
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4358 |         dispatch_info.method_load_kind, | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4359 |         HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, | 
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4360 |         dispatch_info.method_load_data, | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4361 |         0u | 
 | 4362 |       }; | 
 | 4363 |     default: | 
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4364 |       return dispatch_info; | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4365 |   } | 
 | 4366 | } | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4367 |  | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4368 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, | 
 | 4369 |                                                                  Register temp) { | 
 | 4370 |   DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4371 |   Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4372 |   if (!invoke->GetLocations()->Intrinsified()) { | 
 | 4373 |     return location.AsRegister<Register>(); | 
 | 4374 |   } | 
 | 4375 |   // For intrinsics we allow any location, so it may be on the stack. | 
 | 4376 |   if (!location.IsRegister()) { | 
 | 4377 |     __ movl(temp, Address(ESP, location.GetStackIndex())); | 
 | 4378 |     return temp; | 
 | 4379 |   } | 
 | 4380 |   // For register locations, check if the register was saved. If so, get it from the stack. | 
 | 4381 |   // Note: There is a chance that the register was saved but not overwritten, so we could | 
 | 4382 |   // save one load. However, since this is just an intrinsic slow path we prefer this | 
 | 4383 |   // simple and more robust approach rather that trying to determine if that's the case. | 
 | 4384 |   SlowPathCode* slow_path = GetCurrentSlowPath(); | 
 | 4385 |   DCHECK(slow_path != nullptr);  // For intrinsified invokes the call is emitted on the slow path. | 
 | 4386 |   if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { | 
 | 4387 |     int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); | 
 | 4388 |     __ movl(temp, Address(ESP, stack_offset)); | 
 | 4389 |     return temp; | 
 | 4390 |   } | 
 | 4391 |   return location.AsRegister<Register>(); | 
 | 4392 | } | 
 | 4393 |  | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4394 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { | 
 | 4395 |   Location callee_method = temp;  // For all kinds except kRecursive, callee will be in temp. | 
 | 4396 |   switch (invoke->GetMethodLoadKind()) { | 
 | 4397 |     case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: | 
 | 4398 |       // temp = thread->string_init_entrypoint | 
 | 4399 |       __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); | 
 | 4400 |       break; | 
 | 4401 |     case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4402 |       callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4403 |       break; | 
 | 4404 |     case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: | 
 | 4405 |       __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); | 
 | 4406 |       break; | 
 | 4407 |     case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4408 |       __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4409 |       method_patches_.emplace_back(invoke->GetTargetMethod()); | 
 | 4410 |       __ Bind(&method_patches_.back().label);  // Bind the label at the end of the "movl" insn. | 
 | 4411 |       break; | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4412 |     case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { | 
 | 4413 |       Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, | 
 | 4414 |                                                                 temp.AsRegister<Register>()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4415 |       __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4416 |       // Bind a new fixup label at the end of the "movl" insn. | 
 | 4417 |       uint32_t offset = invoke->GetDexCacheArrayOffset(); | 
 | 4418 |       __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4419 |       break; | 
 | 4420 |     } | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4421 |     case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4422 |       Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4423 |       Register method_reg; | 
 | 4424 |       Register reg = temp.AsRegister<Register>(); | 
 | 4425 |       if (current_method.IsRegister()) { | 
 | 4426 |         method_reg = current_method.AsRegister<Register>(); | 
 | 4427 |       } else { | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4428 |         DCHECK(invoke->GetLocations()->Intrinsified()); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4429 |         DCHECK(!current_method.IsValid()); | 
 | 4430 |         method_reg = reg; | 
 | 4431 |         __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); | 
 | 4432 |       } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4433 |       // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; | 
| Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4434 |       __ movl(reg, Address(method_reg, | 
 | 4435 |                            ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4436 |       // temp = temp[index_in_cache] | 
 | 4437 |       uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; | 
 | 4438 |       __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); | 
 | 4439 |       break; | 
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4440 |     } | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4441 |   } | 
 | 4442 |  | 
 | 4443 |   switch (invoke->GetCodePtrLocation()) { | 
 | 4444 |     case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: | 
 | 4445 |       __ call(GetFrameEntryLabel()); | 
 | 4446 |       break; | 
 | 4447 |     case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { | 
 | 4448 |       relative_call_patches_.emplace_back(invoke->GetTargetMethod()); | 
 | 4449 |       Label* label = &relative_call_patches_.back().label; | 
 | 4450 |       __ call(label);  // Bind to the patch label, override at link time. | 
 | 4451 |       __ Bind(label);  // Bind the label at the end of the "call" insn. | 
 | 4452 |       break; | 
 | 4453 |     } | 
 | 4454 |     case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: | 
 | 4455 |     case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4456 |       // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). | 
 | 4457 |       LOG(FATAL) << "Unsupported"; | 
 | 4458 |       UNREACHABLE(); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4459 |     case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: | 
 | 4460 |       // (callee_method + offset_of_quick_compiled_code)() | 
 | 4461 |       __ call(Address(callee_method.AsRegister<Register>(), | 
 | 4462 |                       ArtMethod::EntryPointFromQuickCompiledCodeOffset( | 
 | 4463 |                           kX86WordSize).Int32Value())); | 
 | 4464 |       break; | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4465 |   } | 
 | 4466 |  | 
 | 4467 |   DCHECK(!IsLeafMethod()); | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4468 | } | 
 | 4469 |  | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4470 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { | 
 | 4471 |   Register temp = temp_in.AsRegister<Register>(); | 
 | 4472 |   uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( | 
 | 4473 |       invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); | 
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4474 |  | 
 | 4475 |   // Use the calling convention instead of the location of the receiver, as | 
 | 4476 |   // intrinsics may have put the receiver in a different register. In the intrinsics | 
 | 4477 |   // slow path, the arguments have been moved to the right place, so here we are | 
 | 4478 |   // guaranteed that the receiver is the first register of the calling convention. | 
 | 4479 |   InvokeDexCallingConvention calling_convention; | 
 | 4480 |   Register receiver = calling_convention.GetRegisterAt(0); | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4481 |   uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4482 |   // /* HeapReference<Class> */ temp = receiver->klass_ | 
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4483 |   __ movl(temp, Address(receiver, class_offset)); | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4484 |   MaybeRecordImplicitNullCheck(invoke); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4485 |   // Instead of simply (possibly) unpoisoning `temp` here, we should | 
 | 4486 |   // emit a read barrier for the previous class reference load. | 
 | 4487 |   // However this is not required in practice, as this is an | 
 | 4488 |   // intermediate/temporary reference and because the current | 
 | 4489 |   // concurrent copying collector keeps the from-space memory | 
 | 4490 |   // intact/accessible until the end of the marking phase (the | 
 | 4491 |   // concurrent copying collector may not in the future). | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4492 |   __ MaybeUnpoisonHeapReference(temp); | 
 | 4493 |   // temp = temp->GetMethodAt(method_offset); | 
 | 4494 |   __ movl(temp, Address(temp, method_offset)); | 
 | 4495 |   // call temp->GetEntryPoint(); | 
 | 4496 |   __ call(Address( | 
 | 4497 |       temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); | 
 | 4498 | } | 
 | 4499 |  | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4500 | void CodeGeneratorX86::RecordSimplePatch() { | 
 | 4501 |   if (GetCompilerOptions().GetIncludePatchInformation()) { | 
 | 4502 |     simple_patches_.emplace_back(); | 
 | 4503 |     __ Bind(&simple_patches_.back()); | 
 | 4504 |   } | 
 | 4505 | } | 
 | 4506 |  | 
 | 4507 | void CodeGeneratorX86::RecordStringPatch(HLoadString* load_string) { | 
 | 4508 |   string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); | 
 | 4509 |   __ Bind(&string_patches_.back().label); | 
 | 4510 | } | 
 | 4511 |  | 
 | 4512 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, | 
 | 4513 |                                                          uint32_t element_offset) { | 
 | 4514 |   // Add the patch entry and bind its label at the end of the instruction. | 
 | 4515 |   pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); | 
 | 4516 |   return &pc_relative_dex_cache_patches_.back().label; | 
 | 4517 | } | 
 | 4518 |  | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4519 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { | 
 | 4520 |   DCHECK(linker_patches->empty()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4521 |   size_t size = | 
 | 4522 |       method_patches_.size() + | 
 | 4523 |       relative_call_patches_.size() + | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4524 |       pc_relative_dex_cache_patches_.size() + | 
 | 4525 |       simple_patches_.size() + | 
 | 4526 |       string_patches_.size(); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4527 |   linker_patches->reserve(size); | 
 | 4528 |   // The label points to the end of the "movl" insn but the literal offset for method | 
 | 4529 |   // patch needs to point to the embedded constant which occupies the last 4 bytes. | 
 | 4530 |   constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4531 |   for (const MethodPatchInfo<Label>& info : method_patches_) { | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4532 |     uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4533 |     linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, | 
 | 4534 |                                                        info.target_method.dex_file, | 
 | 4535 |                                                        info.target_method.dex_method_index)); | 
 | 4536 |   } | 
 | 4537 |   for (const MethodPatchInfo<Label>& info : relative_call_patches_) { | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4538 |     uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4539 |     linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, | 
 | 4540 |                                                              info.target_method.dex_file, | 
 | 4541 |                                                              info.target_method.dex_method_index)); | 
 | 4542 |   } | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4543 |   for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { | 
 | 4544 |     uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; | 
 | 4545 |     linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, | 
 | 4546 |                                                               &info.target_dex_file, | 
 | 4547 |                                                               GetMethodAddressOffset(), | 
 | 4548 |                                                               info.element_offset)); | 
 | 4549 |   } | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4550 |   for (const Label& label : simple_patches_) { | 
 | 4551 |     uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; | 
 | 4552 |     linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); | 
 | 4553 |   } | 
 | 4554 |   if (GetCompilerOptions().GetCompilePic()) { | 
 | 4555 |     for (const StringPatchInfo<Label>& info : string_patches_) { | 
 | 4556 |       uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; | 
 | 4557 |       linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, | 
 | 4558 |                                                                  &info.dex_file, | 
 | 4559 |                                                                  GetMethodAddressOffset(), | 
 | 4560 |                                                                  info.string_index)); | 
 | 4561 |     } | 
 | 4562 |   } else { | 
 | 4563 |     for (const StringPatchInfo<Label>& info : string_patches_) { | 
 | 4564 |       uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; | 
 | 4565 |       linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, | 
 | 4566 |                                                          &info.dex_file, | 
 | 4567 |                                                          info.string_index)); | 
 | 4568 |     } | 
 | 4569 |   } | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4570 | } | 
 | 4571 |  | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4572 | void CodeGeneratorX86::MarkGCCard(Register temp, | 
 | 4573 |                                   Register card, | 
 | 4574 |                                   Register object, | 
 | 4575 |                                   Register value, | 
 | 4576 |                                   bool value_can_be_null) { | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4577 |   NearLabel is_null; | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4578 |   if (value_can_be_null) { | 
 | 4579 |     __ testl(value, value); | 
 | 4580 |     __ j(kEqual, &is_null); | 
 | 4581 |   } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4582 |   __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); | 
 | 4583 |   __ movl(temp, object); | 
 | 4584 |   __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); | 
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4585 |   __ movb(Address(temp, card, TIMES_1, 0), | 
 | 4586 |           X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4587 |   if (value_can_be_null) { | 
 | 4588 |     __ Bind(&is_null); | 
 | 4589 |   } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4590 | } | 
 | 4591 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4592 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { | 
 | 4593 |   DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4594 |  | 
 | 4595 |   bool object_field_get_with_read_barrier = | 
 | 4596 |       kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4597 |   LocationSummary* locations = | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4598 |       new (GetGraph()->GetArena()) LocationSummary(instruction, | 
 | 4599 |                                                    kEmitCompilerReadBarrier ? | 
 | 4600 |                                                        LocationSummary::kCallOnSlowPath : | 
 | 4601 |                                                        LocationSummary::kNoCall); | 
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4602 |   locations->SetInAt(0, Location::RequiresRegister()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4603 |  | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4604 |   if (Primitive::IsFloatingPointType(instruction->GetType())) { | 
 | 4605 |     locations->SetOut(Location::RequiresFpuRegister()); | 
 | 4606 |   } else { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4607 |     // The output overlaps in case of long: we don't want the low move | 
 | 4608 |     // to overwrite the object's location.  Likewise, in the case of | 
 | 4609 |     // an object field get with read barriers enabled, we do not want | 
 | 4610 |     // the move to overwrite the object's location, as we need it to emit | 
 | 4611 |     // the read barrier. | 
 | 4612 |     locations->SetOut( | 
 | 4613 |         Location::RequiresRegister(), | 
 | 4614 |         (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? | 
 | 4615 |             Location::kOutputOverlap : | 
 | 4616 |             Location::kNoOutputOverlap); | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4617 |   } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4618 |  | 
 | 4619 |   if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { | 
 | 4620 |     // Long values can be loaded atomically into an XMM using movsd. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4621 |     // So we use an XMM register as a temp to achieve atomicity (first | 
 | 4622 |     // load the temp into the XMM and then copy the XMM into the | 
 | 4623 |     // output, 32 bits at a time). | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4624 |     locations->AddTemp(Location::RequiresFpuRegister()); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4625 |   } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { | 
 | 4626 |     // We need a temporary register for the read barrier marking slow | 
 | 4627 |     // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. | 
 | 4628 |     locations->AddTemp(Location::RequiresRegister()); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4629 |   } | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4630 | } | 
 | 4631 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4632 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, | 
 | 4633 |                                                  const FieldInfo& field_info) { | 
 | 4634 |   DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4635 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4636 |   LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4637 |   Location base_loc = locations->InAt(0); | 
 | 4638 |   Register base = base_loc.AsRegister<Register>(); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4639 |   Location out = locations->Out(); | 
 | 4640 |   bool is_volatile = field_info.IsVolatile(); | 
 | 4641 |   Primitive::Type field_type = field_info.GetFieldType(); | 
 | 4642 |   uint32_t offset = field_info.GetFieldOffset().Uint32Value(); | 
 | 4643 |  | 
 | 4644 |   switch (field_type) { | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4645 |     case Primitive::kPrimBoolean: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4646 |       __ movzxb(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4647 |       break; | 
 | 4648 |     } | 
 | 4649 |  | 
 | 4650 |     case Primitive::kPrimByte: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4651 |       __ movsxb(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4652 |       break; | 
 | 4653 |     } | 
 | 4654 |  | 
 | 4655 |     case Primitive::kPrimShort: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4656 |       __ movsxw(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4657 |       break; | 
 | 4658 |     } | 
 | 4659 |  | 
 | 4660 |     case Primitive::kPrimChar: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4661 |       __ movzxw(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4662 |       break; | 
 | 4663 |     } | 
 | 4664 |  | 
 | 4665 |     case Primitive::kPrimInt: | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4666 |       __ movl(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4667 |       break; | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4668 |  | 
 | 4669 |     case Primitive::kPrimNot: { | 
 | 4670 |       // /* HeapReference<Object> */ out = *(base + offset) | 
 | 4671 |       if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { | 
 | 4672 |         Location temp_loc = locations->GetTemp(0); | 
 | 4673 |         // Note that a potential implicit null check is handled in this | 
 | 4674 |         // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. | 
 | 4675 |         codegen_->GenerateFieldLoadWithBakerReadBarrier( | 
 | 4676 |             instruction, out, base, offset, temp_loc, /* needs_null_check */ true); | 
 | 4677 |         if (is_volatile) { | 
 | 4678 |           codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); | 
 | 4679 |         } | 
 | 4680 |       } else { | 
 | 4681 |         __ movl(out.AsRegister<Register>(), Address(base, offset)); | 
 | 4682 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 4683 |         if (is_volatile) { | 
 | 4684 |           codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); | 
 | 4685 |         } | 
 | 4686 |         // If read barriers are enabled, emit read barriers other than | 
 | 4687 |         // Baker's using a slow path (and also unpoison the loaded | 
 | 4688 |         // reference, if heap poisoning is enabled). | 
 | 4689 |         codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); | 
 | 4690 |       } | 
 | 4691 |       break; | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4692 |     } | 
 | 4693 |  | 
 | 4694 |     case Primitive::kPrimLong: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4695 |       if (is_volatile) { | 
 | 4696 |         XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
 | 4697 |         __ movsd(temp, Address(base, offset)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4698 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4699 |         __ movd(out.AsRegisterPairLow<Register>(), temp); | 
 | 4700 |         __ psrlq(temp, Immediate(32)); | 
 | 4701 |         __ movd(out.AsRegisterPairHigh<Register>(), temp); | 
 | 4702 |       } else { | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4703 |         DCHECK_NE(base, out.AsRegisterPairLow<Register>()); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4704 |         __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4705 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4706 |         __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); | 
 | 4707 |       } | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4708 |       break; | 
 | 4709 |     } | 
 | 4710 |  | 
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4711 |     case Primitive::kPrimFloat: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4712 |       __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); | 
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4713 |       break; | 
 | 4714 |     } | 
 | 4715 |  | 
 | 4716 |     case Primitive::kPrimDouble: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4717 |       __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); | 
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4718 |       break; | 
 | 4719 |     } | 
 | 4720 |  | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4721 |     case Primitive::kPrimVoid: | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4722 |       LOG(FATAL) << "Unreachable type " << field_type; | 
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4723 |       UNREACHABLE(); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4724 |   } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4725 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4726 |   if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { | 
 | 4727 |     // Potential implicit null checks, in the case of reference or | 
 | 4728 |     // long fields, are handled in the previous switch statement. | 
 | 4729 |   } else { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4730 |     codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 4731 |   } | 
 | 4732 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4733 |   if (is_volatile) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4734 |     if (field_type == Primitive::kPrimNot) { | 
 | 4735 |       // Memory barriers, in the case of references, are also handled | 
 | 4736 |       // in the previous switch statement. | 
 | 4737 |     } else { | 
 | 4738 |       codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); | 
 | 4739 |     } | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4740 |   } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4741 | } | 
 | 4742 |  | 
 | 4743 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { | 
 | 4744 |   DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); | 
 | 4745 |  | 
 | 4746 |   LocationSummary* locations = | 
 | 4747 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
 | 4748 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 4749 |   bool is_volatile = field_info.IsVolatile(); | 
 | 4750 |   Primitive::Type field_type = field_info.GetFieldType(); | 
 | 4751 |   bool is_byte_type = (field_type == Primitive::kPrimBoolean) | 
 | 4752 |     || (field_type == Primitive::kPrimByte); | 
 | 4753 |  | 
 | 4754 |   // The register allocator does not support multiple | 
 | 4755 |   // inputs that die at entry with one in a specific register. | 
 | 4756 |   if (is_byte_type) { | 
 | 4757 |     // Ensure the value is in a byte register. | 
 | 4758 |     locations->SetInAt(1, Location::RegisterLocation(EAX)); | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4759 |   } else if (Primitive::IsFloatingPointType(field_type)) { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4760 |     if (is_volatile && field_type == Primitive::kPrimDouble) { | 
 | 4761 |       // In order to satisfy the semantics of volatile, this must be a single instruction store. | 
 | 4762 |       locations->SetInAt(1, Location::RequiresFpuRegister()); | 
 | 4763 |     } else { | 
 | 4764 |       locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); | 
 | 4765 |     } | 
 | 4766 |   } else if (is_volatile && field_type == Primitive::kPrimLong) { | 
 | 4767 |     // In order to satisfy the semantics of volatile, this must be a single instruction store. | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4768 |     locations->SetInAt(1, Location::RequiresRegister()); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4769 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4770 |     // 64bits value can be atomically written to an address with movsd and an XMM register. | 
 | 4771 |     // We need two XMM registers because there's no easier way to (bit) copy a register pair | 
 | 4772 |     // into a single XMM register (we copy each pair part into the XMMs and then interleave them). | 
 | 4773 |     // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the | 
 | 4774 |     // isolated cases when we need this it isn't worth adding the extra complexity. | 
 | 4775 |     locations->AddTemp(Location::RequiresFpuRegister()); | 
 | 4776 |     locations->AddTemp(Location::RequiresFpuRegister()); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4777 |   } else { | 
 | 4778 |     locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
 | 4779 |  | 
 | 4780 |     if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { | 
 | 4781 |       // Temporary registers for the write barrier. | 
 | 4782 |       locations->AddTemp(Location::RequiresRegister());  // May be used for reference poisoning too. | 
 | 4783 |       // Ensure the card is in a byte register. | 
 | 4784 |       locations->AddTemp(Location::RegisterLocation(ECX)); | 
 | 4785 |     } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4786 |   } | 
 | 4787 | } | 
 | 4788 |  | 
 | 4789 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4790 |                                                  const FieldInfo& field_info, | 
 | 4791 |                                                  bool value_can_be_null) { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4792 |   DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); | 
 | 4793 |  | 
 | 4794 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 4795 |   Register base = locations->InAt(0).AsRegister<Register>(); | 
 | 4796 |   Location value = locations->InAt(1); | 
 | 4797 |   bool is_volatile = field_info.IsVolatile(); | 
 | 4798 |   Primitive::Type field_type = field_info.GetFieldType(); | 
 | 4799 |   uint32_t offset = field_info.GetFieldOffset().Uint32Value(); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4800 |   bool needs_write_barrier = | 
 | 4801 |       CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4802 |  | 
 | 4803 |   if (is_volatile) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4804 |     codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4805 |   } | 
 | 4806 |  | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4807 |   bool maybe_record_implicit_null_check_done = false; | 
 | 4808 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4809 |   switch (field_type) { | 
 | 4810 |     case Primitive::kPrimBoolean: | 
 | 4811 |     case Primitive::kPrimByte: { | 
 | 4812 |       __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); | 
 | 4813 |       break; | 
 | 4814 |     } | 
 | 4815 |  | 
 | 4816 |     case Primitive::kPrimShort: | 
 | 4817 |     case Primitive::kPrimChar: { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4818 |       if (value.IsConstant()) { | 
 | 4819 |         int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); | 
 | 4820 |         __ movw(Address(base, offset), Immediate(v)); | 
 | 4821 |       } else { | 
 | 4822 |         __ movw(Address(base, offset), value.AsRegister<Register>()); | 
 | 4823 |       } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4824 |       break; | 
 | 4825 |     } | 
 | 4826 |  | 
 | 4827 |     case Primitive::kPrimInt: | 
 | 4828 |     case Primitive::kPrimNot: { | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4829 |       if (kPoisonHeapReferences && needs_write_barrier) { | 
 | 4830 |         // Note that in the case where `value` is a null reference, | 
 | 4831 |         // we do not enter this block, as the reference does not | 
 | 4832 |         // need poisoning. | 
 | 4833 |         DCHECK_EQ(field_type, Primitive::kPrimNot); | 
 | 4834 |         Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
 | 4835 |         __ movl(temp, value.AsRegister<Register>()); | 
 | 4836 |         __ PoisonHeapReference(temp); | 
 | 4837 |         __ movl(Address(base, offset), temp); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4838 |       } else if (value.IsConstant()) { | 
 | 4839 |         int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); | 
 | 4840 |         __ movl(Address(base, offset), Immediate(v)); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4841 |       } else { | 
| Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4842 |         DCHECK(value.IsRegister()) << value; | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4843 |         __ movl(Address(base, offset), value.AsRegister<Register>()); | 
 | 4844 |       } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4845 |       break; | 
 | 4846 |     } | 
 | 4847 |  | 
 | 4848 |     case Primitive::kPrimLong: { | 
 | 4849 |       if (is_volatile) { | 
 | 4850 |         XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
 | 4851 |         XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); | 
 | 4852 |         __ movd(temp1, value.AsRegisterPairLow<Register>()); | 
 | 4853 |         __ movd(temp2, value.AsRegisterPairHigh<Register>()); | 
 | 4854 |         __ punpckldq(temp1, temp2); | 
 | 4855 |         __ movsd(Address(base, offset), temp1); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4856 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4857 |       } else if (value.IsConstant()) { | 
 | 4858 |         int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); | 
 | 4859 |         __ movl(Address(base, offset), Immediate(Low32Bits(v))); | 
 | 4860 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 4861 |         __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4862 |       } else { | 
 | 4863 |         __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4864 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4865 |         __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); | 
 | 4866 |       } | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4867 |       maybe_record_implicit_null_check_done = true; | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4868 |       break; | 
 | 4869 |     } | 
 | 4870 |  | 
 | 4871 |     case Primitive::kPrimFloat: { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4872 |       if (value.IsConstant()) { | 
 | 4873 |         int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); | 
 | 4874 |         __ movl(Address(base, offset), Immediate(v)); | 
 | 4875 |       } else { | 
 | 4876 |         __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); | 
 | 4877 |       } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4878 |       break; | 
 | 4879 |     } | 
 | 4880 |  | 
 | 4881 |     case Primitive::kPrimDouble: { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4882 |       if (value.IsConstant()) { | 
 | 4883 |         int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); | 
 | 4884 |         __ movl(Address(base, offset), Immediate(Low32Bits(v))); | 
 | 4885 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 4886 |         __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); | 
 | 4887 |         maybe_record_implicit_null_check_done = true; | 
 | 4888 |       } else { | 
 | 4889 |         __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); | 
 | 4890 |       } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4891 |       break; | 
 | 4892 |     } | 
 | 4893 |  | 
 | 4894 |     case Primitive::kPrimVoid: | 
 | 4895 |       LOG(FATAL) << "Unreachable type " << field_type; | 
 | 4896 |       UNREACHABLE(); | 
 | 4897 |   } | 
 | 4898 |  | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4899 |   if (!maybe_record_implicit_null_check_done) { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4900 |     codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 4901 |   } | 
 | 4902 |  | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4903 |   if (needs_write_barrier) { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4904 |     Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
 | 4905 |     Register card = locations->GetTemp(1).AsRegister<Register>(); | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4906 |     codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4907 |   } | 
 | 4908 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4909 |   if (is_volatile) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4910 |     codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4911 |   } | 
 | 4912 | } | 
 | 4913 |  | 
 | 4914 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
 | 4915 |   HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
 | 4916 | } | 
 | 4917 |  | 
 | 4918 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
 | 4919 |   HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
 | 4920 | } | 
 | 4921 |  | 
 | 4922 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
 | 4923 |   HandleFieldSet(instruction, instruction->GetFieldInfo()); | 
 | 4924 | } | 
 | 4925 |  | 
 | 4926 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4927 |   HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4928 | } | 
 | 4929 |  | 
 | 4930 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
 | 4931 |   HandleFieldSet(instruction, instruction->GetFieldInfo()); | 
 | 4932 | } | 
 | 4933 |  | 
 | 4934 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4935 |   HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4936 | } | 
 | 4937 |  | 
 | 4938 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
 | 4939 |   HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
 | 4940 | } | 
 | 4941 |  | 
 | 4942 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
 | 4943 |   HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4944 | } | 
 | 4945 |  | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4946 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( | 
 | 4947 |     HUnresolvedInstanceFieldGet* instruction) { | 
 | 4948 |   FieldAccessCallingConventionX86 calling_convention; | 
 | 4949 |   codegen_->CreateUnresolvedFieldLocationSummary( | 
 | 4950 |       instruction, instruction->GetFieldType(), calling_convention); | 
 | 4951 | } | 
 | 4952 |  | 
 | 4953 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( | 
 | 4954 |     HUnresolvedInstanceFieldGet* instruction) { | 
 | 4955 |   FieldAccessCallingConventionX86 calling_convention; | 
 | 4956 |   codegen_->GenerateUnresolvedFieldAccess(instruction, | 
 | 4957 |                                           instruction->GetFieldType(), | 
 | 4958 |                                           instruction->GetFieldIndex(), | 
 | 4959 |                                           instruction->GetDexPc(), | 
 | 4960 |                                           calling_convention); | 
 | 4961 | } | 
 | 4962 |  | 
 | 4963 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( | 
 | 4964 |     HUnresolvedInstanceFieldSet* instruction) { | 
 | 4965 |   FieldAccessCallingConventionX86 calling_convention; | 
 | 4966 |   codegen_->CreateUnresolvedFieldLocationSummary( | 
 | 4967 |       instruction, instruction->GetFieldType(), calling_convention); | 
 | 4968 | } | 
 | 4969 |  | 
 | 4970 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( | 
 | 4971 |     HUnresolvedInstanceFieldSet* instruction) { | 
 | 4972 |   FieldAccessCallingConventionX86 calling_convention; | 
 | 4973 |   codegen_->GenerateUnresolvedFieldAccess(instruction, | 
 | 4974 |                                           instruction->GetFieldType(), | 
 | 4975 |                                           instruction->GetFieldIndex(), | 
 | 4976 |                                           instruction->GetDexPc(), | 
 | 4977 |                                           calling_convention); | 
 | 4978 | } | 
 | 4979 |  | 
 | 4980 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( | 
 | 4981 |     HUnresolvedStaticFieldGet* instruction) { | 
 | 4982 |   FieldAccessCallingConventionX86 calling_convention; | 
 | 4983 |   codegen_->CreateUnresolvedFieldLocationSummary( | 
 | 4984 |       instruction, instruction->GetFieldType(), calling_convention); | 
 | 4985 | } | 
 | 4986 |  | 
 | 4987 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( | 
 | 4988 |     HUnresolvedStaticFieldGet* instruction) { | 
 | 4989 |   FieldAccessCallingConventionX86 calling_convention; | 
 | 4990 |   codegen_->GenerateUnresolvedFieldAccess(instruction, | 
 | 4991 |                                           instruction->GetFieldType(), | 
 | 4992 |                                           instruction->GetFieldIndex(), | 
 | 4993 |                                           instruction->GetDexPc(), | 
 | 4994 |                                           calling_convention); | 
 | 4995 | } | 
 | 4996 |  | 
 | 4997 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( | 
 | 4998 |     HUnresolvedStaticFieldSet* instruction) { | 
 | 4999 |   FieldAccessCallingConventionX86 calling_convention; | 
 | 5000 |   codegen_->CreateUnresolvedFieldLocationSummary( | 
 | 5001 |       instruction, instruction->GetFieldType(), calling_convention); | 
 | 5002 | } | 
 | 5003 |  | 
 | 5004 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( | 
 | 5005 |     HUnresolvedStaticFieldSet* instruction) { | 
 | 5006 |   FieldAccessCallingConventionX86 calling_convention; | 
 | 5007 |   codegen_->GenerateUnresolvedFieldAccess(instruction, | 
 | 5008 |                                           instruction->GetFieldType(), | 
 | 5009 |                                           instruction->GetFieldIndex(), | 
 | 5010 |                                           instruction->GetDexPc(), | 
 | 5011 |                                           calling_convention); | 
 | 5012 | } | 
 | 5013 |  | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5014 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5015 |   LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
 | 5016 |       ? LocationSummary::kCallOnSlowPath | 
 | 5017 |       : LocationSummary::kNoCall; | 
 | 5018 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
 | 5019 |   Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5020 |       ? Location::RequiresRegister() | 
 | 5021 |       : Location::Any(); | 
 | 5022 |   locations->SetInAt(0, loc); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5023 |   if (instruction->HasUses()) { | 
 | 5024 |     locations->SetOut(Location::SameAsFirstInput()); | 
 | 5025 |   } | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5026 | } | 
 | 5027 |  | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5028 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { | 
 | 5029 |   if (CanMoveNullCheckToUser(instruction)) { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5030 |     return; | 
 | 5031 |   } | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5032 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 5033 |   Location obj = locations->InAt(0); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5034 |  | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5035 |   __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5036 |   RecordPcInfo(instruction, instruction->GetDexPc()); | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5037 | } | 
 | 5038 |  | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5039 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5040 |   SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5041 |   AddSlowPath(slow_path); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5042 |  | 
 | 5043 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 5044 |   Location obj = locations->InAt(0); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5045 |  | 
 | 5046 |   if (obj.IsRegister()) { | 
| Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5047 |     __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5048 |   } else if (obj.IsStackSlot()) { | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5049 |     __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5050 |   } else { | 
 | 5051 |     DCHECK(obj.IsConstant()) << obj; | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5052 |     DCHECK(obj.GetConstant()->IsNullConstant()); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5053 |     __ jmp(slow_path->GetEntryLabel()); | 
 | 5054 |     return; | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5055 |   } | 
 | 5056 |   __ j(kEqual, slow_path->GetEntryLabel()); | 
 | 5057 | } | 
 | 5058 |  | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5059 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5060 |   codegen_->GenerateNullCheck(instruction); | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5061 | } | 
 | 5062 |  | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5063 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5064 |   bool object_array_get_with_read_barrier = | 
 | 5065 |       kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5066 |   LocationSummary* locations = | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5067 |       new (GetGraph()->GetArena()) LocationSummary(instruction, | 
 | 5068 |                                                    object_array_get_with_read_barrier ? | 
 | 5069 |                                                        LocationSummary::kCallOnSlowPath : | 
 | 5070 |                                                        LocationSummary::kNoCall); | 
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5071 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 5072 |   locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5073 |   if (Primitive::IsFloatingPointType(instruction->GetType())) { | 
 | 5074 |     locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
 | 5075 |   } else { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5076 |     // The output overlaps in case of long: we don't want the low move | 
 | 5077 |     // to overwrite the array's location.  Likewise, in the case of an | 
 | 5078 |     // object array get with read barriers enabled, we do not want the | 
 | 5079 |     // move to overwrite the array's location, as we need it to emit | 
 | 5080 |     // the read barrier. | 
 | 5081 |     locations->SetOut( | 
 | 5082 |         Location::RequiresRegister(), | 
 | 5083 |         (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? | 
 | 5084 |             Location::kOutputOverlap : | 
 | 5085 |             Location::kNoOutputOverlap); | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5086 |   } | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5087 |   // We need a temporary register for the read barrier marking slow | 
 | 5088 |   // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. | 
 | 5089 |   if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { | 
 | 5090 |     locations->AddTemp(Location::RequiresRegister()); | 
 | 5091 |   } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5092 | } | 
 | 5093 |  | 
 | 5094 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { | 
 | 5095 |   LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5096 |   Location obj_loc = locations->InAt(0); | 
 | 5097 |   Register obj = obj_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5098 |   Location index = locations->InAt(1); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5099 |   Location out_loc = locations->Out(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5100 |  | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5101 |   Primitive::Type type = instruction->GetType(); | 
 | 5102 |   switch (type) { | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5103 |     case Primitive::kPrimBoolean: { | 
 | 5104 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5105 |       Register out = out_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5106 |       if (index.IsConstant()) { | 
 | 5107 |         __ movzxb(out, Address(obj, | 
 | 5108 |             (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); | 
 | 5109 |       } else { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5110 |         __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 |       } | 
 | 5112 |       break; | 
 | 5113 |     } | 
 | 5114 |  | 
 | 5115 |     case Primitive::kPrimByte: { | 
 | 5116 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5117 |       Register out = out_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5118 |       if (index.IsConstant()) { | 
 | 5119 |         __ movsxb(out, Address(obj, | 
 | 5120 |             (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); | 
 | 5121 |       } else { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5122 |         __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5123 |       } | 
 | 5124 |       break; | 
 | 5125 |     } | 
 | 5126 |  | 
 | 5127 |     case Primitive::kPrimShort: { | 
 | 5128 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5129 |       Register out = out_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5130 |       if (index.IsConstant()) { | 
 | 5131 |         __ movsxw(out, Address(obj, | 
 | 5132 |             (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); | 
 | 5133 |       } else { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5134 |         __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5135 |       } | 
 | 5136 |       break; | 
 | 5137 |     } | 
 | 5138 |  | 
 | 5139 |     case Primitive::kPrimChar: { | 
 | 5140 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5141 |       Register out = out_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5142 |       if (index.IsConstant()) { | 
 | 5143 |         __ movzxw(out, Address(obj, | 
 | 5144 |             (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); | 
 | 5145 |       } else { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5146 |         __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5147 |       } | 
 | 5148 |       break; | 
 | 5149 |     } | 
 | 5150 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5151 |     case Primitive::kPrimInt: { | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5152 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5153 |       Register out = out_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5154 |       if (index.IsConstant()) { | 
 | 5155 |         __ movl(out, Address(obj, | 
 | 5156 |             (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); | 
 | 5157 |       } else { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5158 |         __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5159 |       } | 
 | 5160 |       break; | 
 | 5161 |     } | 
 | 5162 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5163 |     case Primitive::kPrimNot: { | 
 | 5164 |       static_assert( | 
 | 5165 |           sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), | 
 | 5166 |           "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); | 
 | 5167 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); | 
 | 5168 |       // /* HeapReference<Object> */ out = | 
 | 5169 |       //     *(obj + data_offset + index * sizeof(HeapReference<Object>)) | 
 | 5170 |       if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { | 
 | 5171 |         Location temp = locations->GetTemp(0); | 
 | 5172 |         // Note that a potential implicit null check is handled in this | 
 | 5173 |         // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. | 
 | 5174 |         codegen_->GenerateArrayLoadWithBakerReadBarrier( | 
 | 5175 |             instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); | 
 | 5176 |       } else { | 
 | 5177 |         Register out = out_loc.AsRegister<Register>(); | 
 | 5178 |         if (index.IsConstant()) { | 
 | 5179 |           uint32_t offset = | 
 | 5180 |               (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
 | 5181 |           __ movl(out, Address(obj, offset)); | 
 | 5182 |           codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 5183 |           // If read barriers are enabled, emit read barriers other than | 
 | 5184 |           // Baker's using a slow path (and also unpoison the loaded | 
 | 5185 |           // reference, if heap poisoning is enabled). | 
 | 5186 |           codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); | 
 | 5187 |         } else { | 
 | 5188 |           __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); | 
 | 5189 |           codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 5190 |           // If read barriers are enabled, emit read barriers other than | 
 | 5191 |           // Baker's using a slow path (and also unpoison the loaded | 
 | 5192 |           // reference, if heap poisoning is enabled). | 
 | 5193 |           codegen_->MaybeGenerateReadBarrierSlow( | 
 | 5194 |               instruction, out_loc, out_loc, obj_loc, data_offset, index); | 
 | 5195 |         } | 
 | 5196 |       } | 
 | 5197 |       break; | 
 | 5198 |     } | 
 | 5199 |  | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5200 |     case Primitive::kPrimLong: { | 
 | 5201 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5202 |       DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5203 |       if (index.IsConstant()) { | 
 | 5204 |         size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5205 |         __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5206 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5207 |         __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5208 |       } else { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5209 |         __ movl(out_loc.AsRegisterPairLow<Register>(), | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5210 |                 Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5211 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5212 |         __ movl(out_loc.AsRegisterPairHigh<Register>(), | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5213 |                 Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5214 |       } | 
 | 5215 |       break; | 
 | 5216 |     } | 
 | 5217 |  | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5218 |     case Primitive::kPrimFloat: { | 
 | 5219 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5220 |       XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5221 |       if (index.IsConstant()) { | 
 | 5222 |         __ movss(out, Address(obj, | 
 | 5223 |             (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); | 
 | 5224 |       } else { | 
 | 5225 |         __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); | 
 | 5226 |       } | 
 | 5227 |       break; | 
 | 5228 |     } | 
 | 5229 |  | 
 | 5230 |     case Primitive::kPrimDouble: { | 
 | 5231 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5232 |       XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5233 |       if (index.IsConstant()) { | 
 | 5234 |         __ movsd(out, Address(obj, | 
 | 5235 |             (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); | 
 | 5236 |       } else { | 
 | 5237 |         __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); | 
 | 5238 |       } | 
 | 5239 |       break; | 
 | 5240 |     } | 
 | 5241 |  | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5242 |     case Primitive::kPrimVoid: | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5243 |       LOG(FATAL) << "Unreachable type " << type; | 
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5244 |       UNREACHABLE(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5245 |   } | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5246 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5247 |   if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { | 
 | 5248 |     // Potential implicit null checks, in the case of reference or | 
 | 5249 |     // long arrays, are handled in the previous switch statement. | 
 | 5250 |   } else { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5251 |     codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 5252 |   } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5253 | } | 
 | 5254 |  | 
 | 5255 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5256 |   Primitive::Type value_type = instruction->GetComponentType(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5257 |  | 
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5258 |   bool needs_write_barrier = | 
 | 5259 |       CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5260 |   bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); | 
 | 5261 |   bool object_array_set_with_read_barrier = | 
 | 5262 |       kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); | 
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5263 |  | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5264 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( | 
 | 5265 |       instruction, | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5266 |       (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? | 
 | 5267 |           LocationSummary::kCallOnSlowPath : | 
 | 5268 |           LocationSummary::kNoCall); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5269 |  | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5270 |   bool is_byte_type = (value_type == Primitive::kPrimBoolean) | 
 | 5271 |       || (value_type == Primitive::kPrimByte); | 
 | 5272 |   // We need the inputs to be different than the output in case of long operation. | 
 | 5273 |   // In case of a byte operation, the register allocator does not support multiple | 
 | 5274 |   // inputs that die at entry with one in a specific register. | 
 | 5275 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 5276 |   locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
 | 5277 |   if (is_byte_type) { | 
 | 5278 |     // Ensure the value is in a byte register. | 
 | 5279 |     locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); | 
 | 5280 |   } else if (Primitive::IsFloatingPointType(value_type)) { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5281 |     locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5282 |   } else { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5283 |     locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); | 
 | 5284 |   } | 
 | 5285 |   if (needs_write_barrier) { | 
 | 5286 |     // Temporary registers for the write barrier. | 
 | 5287 |     locations->AddTemp(Location::RequiresRegister());  // Possibly used for ref. poisoning too. | 
 | 5288 |     // Ensure the card is in a byte register. | 
| Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5289 |     locations->AddTemp(Location::RegisterLocation(ECX)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5290 |   } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5291 | } | 
 | 5292 |  | 
 | 5293 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { | 
 | 5294 |   LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5295 |   Location array_loc = locations->InAt(0); | 
 | 5296 |   Register array = array_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5297 |   Location index = locations->InAt(1); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5298 |   Location value = locations->InAt(2); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5299 |   Primitive::Type value_type = instruction->GetComponentType(); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5300 |   uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
 | 5301 |   uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); | 
 | 5302 |   uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5303 |   bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); | 
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5304 |   bool needs_write_barrier = | 
 | 5305 |       CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5306 |  | 
 | 5307 |   switch (value_type) { | 
 | 5308 |     case Primitive::kPrimBoolean: | 
 | 5309 |     case Primitive::kPrimByte: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5310 |       uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); | 
 | 5311 |       Address address = index.IsConstant() | 
 | 5312 |           ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) | 
 | 5313 |           : Address(array, index.AsRegister<Register>(), TIMES_1, offset); | 
 | 5314 |       if (value.IsRegister()) { | 
 | 5315 |         __ movb(address, value.AsRegister<ByteRegister>()); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5316 |       } else { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5317 |         __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5318 |       } | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5319 |       codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5320 |       break; | 
 | 5321 |     } | 
 | 5322 |  | 
 | 5323 |     case Primitive::kPrimShort: | 
 | 5324 |     case Primitive::kPrimChar: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5325 |       uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); | 
 | 5326 |       Address address = index.IsConstant() | 
 | 5327 |           ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) | 
 | 5328 |           : Address(array, index.AsRegister<Register>(), TIMES_2, offset); | 
 | 5329 |       if (value.IsRegister()) { | 
 | 5330 |         __ movw(address, value.AsRegister<Register>()); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5331 |       } else { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5332 |         __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5333 |       } | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5334 |       codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5335 |       break; | 
 | 5336 |     } | 
 | 5337 |  | 
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5338 |     case Primitive::kPrimNot: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5339 |       uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); | 
 | 5340 |       Address address = index.IsConstant() | 
 | 5341 |           ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) | 
 | 5342 |           : Address(array, index.AsRegister<Register>(), TIMES_4, offset); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5343 |  | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5344 |       if (!value.IsRegister()) { | 
 | 5345 |         // Just setting null. | 
 | 5346 |         DCHECK(instruction->InputAt(2)->IsNullConstant()); | 
 | 5347 |         DCHECK(value.IsConstant()) << value; | 
 | 5348 |         __ movl(address, Immediate(0)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5349 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5350 |         DCHECK(!needs_write_barrier); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5351 |         DCHECK(!may_need_runtime_call_for_type_check); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5352 |         break; | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5353 |       } | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5354 |  | 
 | 5355 |       DCHECK(needs_write_barrier); | 
 | 5356 |       Register register_value = value.AsRegister<Register>(); | 
 | 5357 |       NearLabel done, not_null, do_put; | 
 | 5358 |       SlowPathCode* slow_path = nullptr; | 
 | 5359 |       Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5360 |       if (may_need_runtime_call_for_type_check) { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5361 |         slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); | 
 | 5362 |         codegen_->AddSlowPath(slow_path); | 
 | 5363 |         if (instruction->GetValueCanBeNull()) { | 
 | 5364 |           __ testl(register_value, register_value); | 
 | 5365 |           __ j(kNotEqual, ¬_null); | 
 | 5366 |           __ movl(address, Immediate(0)); | 
 | 5367 |           codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 5368 |           __ jmp(&done); | 
 | 5369 |           __ Bind(¬_null); | 
 | 5370 |         } | 
 | 5371 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5372 |         if (kEmitCompilerReadBarrier) { | 
 | 5373 |           // When read barriers are enabled, the type checking | 
 | 5374 |           // instrumentation requires two read barriers: | 
 | 5375 |           // | 
 | 5376 |           //   __ movl(temp2, temp); | 
 | 5377 |           //   // /* HeapReference<Class> */ temp = temp->component_type_ | 
 | 5378 |           //   __ movl(temp, Address(temp, component_offset)); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5379 |           //   codegen_->GenerateReadBarrierSlow( | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5380 |           //       instruction, temp_loc, temp_loc, temp2_loc, component_offset); | 
 | 5381 |           // | 
 | 5382 |           //   // /* HeapReference<Class> */ temp2 = register_value->klass_ | 
 | 5383 |           //   __ movl(temp2, Address(register_value, class_offset)); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5384 |           //   codegen_->GenerateReadBarrierSlow( | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5385 |           //       instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); | 
 | 5386 |           // | 
 | 5387 |           //   __ cmpl(temp, temp2); | 
 | 5388 |           // | 
 | 5389 |           // However, the second read barrier may trash `temp`, as it | 
 | 5390 |           // is a temporary register, and as such would not be saved | 
 | 5391 |           // along with live registers before calling the runtime (nor | 
 | 5392 |           // restored afterwards).  So in this case, we bail out and | 
 | 5393 |           // delegate the work to the array set slow path. | 
 | 5394 |           // | 
 | 5395 |           // TODO: Extend the register allocator to support a new | 
 | 5396 |           // "(locally) live temp" location so as to avoid always | 
 | 5397 |           // going into the slow path when read barriers are enabled. | 
 | 5398 |           __ jmp(slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5399 |         } else { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5400 |           // /* HeapReference<Class> */ temp = array->klass_ | 
 | 5401 |           __ movl(temp, Address(array, class_offset)); | 
 | 5402 |           codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 5403 |           __ MaybeUnpoisonHeapReference(temp); | 
 | 5404 |  | 
 | 5405 |           // /* HeapReference<Class> */ temp = temp->component_type_ | 
 | 5406 |           __ movl(temp, Address(temp, component_offset)); | 
 | 5407 |           // If heap poisoning is enabled, no need to unpoison `temp` | 
 | 5408 |           // nor the object reference in `register_value->klass`, as | 
 | 5409 |           // we are comparing two poisoned references. | 
 | 5410 |           __ cmpl(temp, Address(register_value, class_offset)); | 
 | 5411 |  | 
 | 5412 |           if (instruction->StaticTypeOfArrayIsObjectArray()) { | 
 | 5413 |             __ j(kEqual, &do_put); | 
 | 5414 |             // If heap poisoning is enabled, the `temp` reference has | 
 | 5415 |             // not been unpoisoned yet; unpoison it now. | 
 | 5416 |             __ MaybeUnpoisonHeapReference(temp); | 
 | 5417 |  | 
 | 5418 |             // /* HeapReference<Class> */ temp = temp->super_class_ | 
 | 5419 |             __ movl(temp, Address(temp, super_offset)); | 
 | 5420 |             // If heap poisoning is enabled, no need to unpoison | 
 | 5421 |             // `temp`, as we are comparing against null below. | 
 | 5422 |             __ testl(temp, temp); | 
 | 5423 |             __ j(kNotEqual, slow_path->GetEntryLabel()); | 
 | 5424 |             __ Bind(&do_put); | 
 | 5425 |           } else { | 
 | 5426 |             __ j(kNotEqual, slow_path->GetEntryLabel()); | 
 | 5427 |           } | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5428 |         } | 
 | 5429 |       } | 
 | 5430 |  | 
 | 5431 |       if (kPoisonHeapReferences) { | 
 | 5432 |         __ movl(temp, register_value); | 
 | 5433 |         __ PoisonHeapReference(temp); | 
 | 5434 |         __ movl(address, temp); | 
 | 5435 |       } else { | 
 | 5436 |         __ movl(address, register_value); | 
 | 5437 |       } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5438 |       if (!may_need_runtime_call_for_type_check) { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5439 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 5440 |       } | 
 | 5441 |  | 
 | 5442 |       Register card = locations->GetTemp(1).AsRegister<Register>(); | 
 | 5443 |       codegen_->MarkGCCard( | 
 | 5444 |           temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); | 
 | 5445 |       __ Bind(&done); | 
 | 5446 |  | 
 | 5447 |       if (slow_path != nullptr) { | 
 | 5448 |         __ Bind(slow_path->GetExitLabel()); | 
 | 5449 |       } | 
 | 5450 |  | 
 | 5451 |       break; | 
 | 5452 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5453 |  | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5454 |     case Primitive::kPrimInt: { | 
 | 5455 |       uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); | 
 | 5456 |       Address address = index.IsConstant() | 
 | 5457 |           ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) | 
 | 5458 |           : Address(array, index.AsRegister<Register>(), TIMES_4, offset); | 
 | 5459 |       if (value.IsRegister()) { | 
 | 5460 |         __ movl(address, value.AsRegister<Register>()); | 
 | 5461 |       } else { | 
 | 5462 |         DCHECK(value.IsConstant()) << value; | 
 | 5463 |         int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); | 
 | 5464 |         __ movl(address, Immediate(v)); | 
 | 5465 |       } | 
 | 5466 |       codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5467 |       break; | 
 | 5468 |     } | 
 | 5469 |  | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5470 |     case Primitive::kPrimLong: { | 
 | 5471 |       uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5472 |       if (index.IsConstant()) { | 
 | 5473 |         size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5474 |         if (value.IsRegisterPair()) { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5475 |           __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5476 |           codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5477 |           __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5478 |         } else { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5479 |           DCHECK(value.IsConstant()); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5480 |           int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5481 |           __ movl(Address(array, offset), Immediate(Low32Bits(val))); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5482 |           codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5483 |           __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5484 |         } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5485 |       } else { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5486 |         if (value.IsRegisterPair()) { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5487 |           __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5488 |                   value.AsRegisterPairLow<Register>()); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5489 |           codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5490 |           __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5491 |                   value.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5492 |         } else { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5493 |           DCHECK(value.IsConstant()); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5494 |           int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5495 |           __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5496 |                   Immediate(Low32Bits(val))); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5497 |           codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5498 |           __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5499 |                   Immediate(High32Bits(val))); | 
 | 5500 |         } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5501 |       } | 
 | 5502 |       break; | 
 | 5503 |     } | 
 | 5504 |  | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5505 |     case Primitive::kPrimFloat: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5506 |       uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); | 
 | 5507 |       Address address = index.IsConstant() | 
 | 5508 |           ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) | 
 | 5509 |           : Address(array, index.AsRegister<Register>(), TIMES_4, offset); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5510 |       if (value.IsFpuRegister()) { | 
 | 5511 |         __ movss(address, value.AsFpuRegister<XmmRegister>()); | 
 | 5512 |       } else { | 
 | 5513 |         DCHECK(value.IsConstant()); | 
 | 5514 |         int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); | 
 | 5515 |         __ movl(address, Immediate(v)); | 
 | 5516 |       } | 
 | 5517 |       codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5518 |       break; | 
 | 5519 |     } | 
 | 5520 |  | 
 | 5521 |     case Primitive::kPrimDouble: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5522 |       uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); | 
 | 5523 |       Address address = index.IsConstant() | 
 | 5524 |           ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) | 
 | 5525 |           : Address(array, index.AsRegister<Register>(), TIMES_8, offset); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5526 |       if (value.IsFpuRegister()) { | 
 | 5527 |         __ movsd(address, value.AsFpuRegister<XmmRegister>()); | 
 | 5528 |       } else { | 
 | 5529 |         DCHECK(value.IsConstant()); | 
 | 5530 |         Address address_hi = index.IsConstant() ? | 
 | 5531 |             Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + | 
 | 5532 |                            offset + kX86WordSize) : | 
 | 5533 |             Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); | 
 | 5534 |         int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); | 
 | 5535 |         __ movl(address, Immediate(Low32Bits(v))); | 
 | 5536 |         codegen_->MaybeRecordImplicitNullCheck(instruction); | 
 | 5537 |         __ movl(address_hi, Immediate(High32Bits(v))); | 
 | 5538 |       } | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5539 |       break; | 
 | 5540 |     } | 
 | 5541 |  | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5542 |     case Primitive::kPrimVoid: | 
 | 5543 |       LOG(FATAL) << "Unreachable type " << instruction->GetType(); | 
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5544 |       UNREACHABLE(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5545 |   } | 
 | 5546 | } | 
 | 5547 |  | 
 | 5548 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { | 
 | 5549 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); | 
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5550 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 5551 |   locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5552 | } | 
 | 5553 |  | 
 | 5554 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { | 
 | 5555 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 5556 |   uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5557 |   Register obj = locations->InAt(0).AsRegister<Register>(); | 
 | 5558 |   Register out = locations->Out().AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5559 |   __ movl(out, Address(obj, offset)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5560 |   codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5561 | } | 
 | 5562 |  | 
 | 5563 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5564 |   LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() | 
 | 5565 |       ? LocationSummary::kCallOnSlowPath | 
 | 5566 |       : LocationSummary::kNoCall; | 
 | 5567 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5568 |   locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); | 
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5569 |   locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5570 |   if (instruction->HasUses()) { | 
 | 5571 |     locations->SetOut(Location::SameAsFirstInput()); | 
 | 5572 |   } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5573 | } | 
 | 5574 |  | 
 | 5575 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { | 
 | 5576 |   LocationSummary* locations = instruction->GetLocations(); | 
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5577 |   Location index_loc = locations->InAt(0); | 
 | 5578 |   Location length_loc = locations->InAt(1); | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5579 |   SlowPathCode* slow_path = | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5580 |     new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5581 |  | 
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5582 |   if (length_loc.IsConstant()) { | 
 | 5583 |     int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); | 
 | 5584 |     if (index_loc.IsConstant()) { | 
 | 5585 |       // BCE will remove the bounds check if we are guarenteed to pass. | 
 | 5586 |       int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); | 
 | 5587 |       if (index < 0 || index >= length) { | 
 | 5588 |         codegen_->AddSlowPath(slow_path); | 
 | 5589 |         __ jmp(slow_path->GetEntryLabel()); | 
 | 5590 |       } else { | 
 | 5591 |         // Some optimization after BCE may have generated this, and we should not | 
 | 5592 |         // generate a bounds check if it is a valid range. | 
 | 5593 |       } | 
 | 5594 |       return; | 
 | 5595 |     } | 
 | 5596 |  | 
 | 5597 |     // We have to reverse the jump condition because the length is the constant. | 
 | 5598 |     Register index_reg = index_loc.AsRegister<Register>(); | 
 | 5599 |     __ cmpl(index_reg, Immediate(length)); | 
 | 5600 |     codegen_->AddSlowPath(slow_path); | 
 | 5601 |     __ j(kAboveEqual, slow_path->GetEntryLabel()); | 
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5602 |   } else { | 
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5603 |     Register length = length_loc.AsRegister<Register>(); | 
 | 5604 |     if (index_loc.IsConstant()) { | 
 | 5605 |       int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); | 
 | 5606 |       __ cmpl(length, Immediate(value)); | 
 | 5607 |     } else { | 
 | 5608 |       __ cmpl(length, index_loc.AsRegister<Register>()); | 
 | 5609 |     } | 
 | 5610 |     codegen_->AddSlowPath(slow_path); | 
 | 5611 |     __ j(kBelowEqual, slow_path->GetEntryLabel()); | 
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5612 |   } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5613 | } | 
 | 5614 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5615 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5616 |   LOG(FATAL) << "Unreachable"; | 
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5617 | } | 
 | 5618 |  | 
 | 5619 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5620 |   codegen_->GetMoveResolver()->EmitNativeCode(instruction); | 
 | 5621 | } | 
 | 5622 |  | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5623 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { | 
 | 5624 |   new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); | 
 | 5625 | } | 
 | 5626 |  | 
 | 5627 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5628 |   HBasicBlock* block = instruction->GetBlock(); | 
 | 5629 |   if (block->GetLoopInformation() != nullptr) { | 
 | 5630 |     DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); | 
 | 5631 |     // The back edge will generate the suspend check. | 
 | 5632 |     return; | 
 | 5633 |   } | 
 | 5634 |   if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { | 
 | 5635 |     // The goto will generate the suspend check. | 
 | 5636 |     return; | 
 | 5637 |   } | 
 | 5638 |   GenerateSuspendCheck(instruction, nullptr); | 
 | 5639 | } | 
 | 5640 |  | 
 | 5641 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, | 
 | 5642 |                                                        HBasicBlock* successor) { | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5643 |   SuspendCheckSlowPathX86* slow_path = | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5644 |       down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); | 
 | 5645 |   if (slow_path == nullptr) { | 
 | 5646 |     slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); | 
 | 5647 |     instruction->SetSlowPath(slow_path); | 
 | 5648 |     codegen_->AddSlowPath(slow_path); | 
 | 5649 |     if (successor != nullptr) { | 
 | 5650 |       DCHECK(successor->IsLoopHeader()); | 
 | 5651 |       codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); | 
 | 5652 |     } | 
 | 5653 |   } else { | 
 | 5654 |     DCHECK_EQ(slow_path->GetSuccessor(), successor); | 
 | 5655 |   } | 
 | 5656 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5657 |   __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), | 
 | 5658 |                 Immediate(0)); | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5659 |   if (successor == nullptr) { | 
 | 5660 |     __ j(kNotEqual, slow_path->GetEntryLabel()); | 
 | 5661 |     __ Bind(slow_path->GetReturnLabel()); | 
 | 5662 |   } else { | 
 | 5663 |     __ j(kEqual, codegen_->GetLabelOf(successor)); | 
 | 5664 |     __ jmp(slow_path->GetEntryLabel()); | 
 | 5665 |   } | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5666 | } | 
 | 5667 |  | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5668 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { | 
 | 5669 |   return codegen_->GetAssembler(); | 
 | 5670 | } | 
 | 5671 |  | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5672 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5673 |   ScratchRegisterScope ensure_scratch( | 
 | 5674 |       this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); | 
 | 5675 |   Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); | 
 | 5676 |   int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; | 
 | 5677 |   __ movl(temp_reg, Address(ESP, src + stack_offset)); | 
 | 5678 |   __ movl(Address(ESP, dst + stack_offset), temp_reg); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5679 | } | 
 | 5680 |  | 
 | 5681 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5682 |   ScratchRegisterScope ensure_scratch( | 
 | 5683 |       this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); | 
 | 5684 |   Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); | 
 | 5685 |   int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; | 
 | 5686 |   __ movl(temp_reg, Address(ESP, src + stack_offset)); | 
 | 5687 |   __ movl(Address(ESP, dst + stack_offset), temp_reg); | 
 | 5688 |   __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); | 
 | 5689 |   __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5690 | } | 
 | 5691 |  | 
 | 5692 | void ParallelMoveResolverX86::EmitMove(size_t index) { | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5693 |   MoveOperands* move = moves_[index]; | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5694 |   Location source = move->GetSource(); | 
 | 5695 |   Location destination = move->GetDestination(); | 
 | 5696 |  | 
 | 5697 |   if (source.IsRegister()) { | 
 | 5698 |     if (destination.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5699 |       __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5700 |     } else if (destination.IsFpuRegister()) { | 
 | 5701 |       __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5702 |     } else { | 
 | 5703 |       DCHECK(destination.IsStackSlot()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5704 |       __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5705 |     } | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5706 |   } else if (source.IsRegisterPair()) { | 
 | 5707 |       size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); | 
 | 5708 |       // Create stack space for 2 elements. | 
 | 5709 |       __ subl(ESP, Immediate(2 * elem_size)); | 
 | 5710 |       __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); | 
 | 5711 |       __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); | 
 | 5712 |       __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); | 
 | 5713 |       // And remove the temporary stack space we allocated. | 
 | 5714 |       __ addl(ESP, Immediate(2 * elem_size)); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5715 |   } else if (source.IsFpuRegister()) { | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5716 |     if (destination.IsRegister()) { | 
 | 5717 |       __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); | 
 | 5718 |     } else if (destination.IsFpuRegister()) { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5719 |       __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5720 |     } else if (destination.IsRegisterPair()) { | 
 | 5721 |       XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); | 
 | 5722 |       __ movd(destination.AsRegisterPairLow<Register>(), src_reg); | 
 | 5723 |       __ psrlq(src_reg, Immediate(32)); | 
 | 5724 |       __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5725 |     } else if (destination.IsStackSlot()) { | 
 | 5726 |       __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); | 
 | 5727 |     } else { | 
 | 5728 |       DCHECK(destination.IsDoubleStackSlot()); | 
 | 5729 |       __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); | 
 | 5730 |     } | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5731 |   } else if (source.IsStackSlot()) { | 
 | 5732 |     if (destination.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5733 |       __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5734 |     } else if (destination.IsFpuRegister()) { | 
 | 5735 |       __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5736 |     } else { | 
 | 5737 |       DCHECK(destination.IsStackSlot()); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5738 |       MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); | 
 | 5739 |     } | 
 | 5740 |   } else if (source.IsDoubleStackSlot()) { | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5741 |     if (destination.IsRegisterPair()) { | 
 | 5742 |       __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); | 
 | 5743 |       __ movl(destination.AsRegisterPairHigh<Register>(), | 
 | 5744 |               Address(ESP, source.GetHighStackIndex(kX86WordSize))); | 
 | 5745 |     } else if (destination.IsFpuRegister()) { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5746 |       __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); | 
 | 5747 |     } else { | 
 | 5748 |       DCHECK(destination.IsDoubleStackSlot()) << destination; | 
 | 5749 |       MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5750 |     } | 
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5751 |   } else if (source.IsConstant()) { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5752 |     HConstant* constant = source.GetConstant(); | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5753 |     if (constant->IsIntConstant() || constant->IsNullConstant()) { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5754 |       int32_t value = CodeGenerator::GetInt32ValueOf(constant); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5755 |       if (destination.IsRegister()) { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5756 |         if (value == 0) { | 
 | 5757 |           __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); | 
 | 5758 |         } else { | 
 | 5759 |           __ movl(destination.AsRegister<Register>(), Immediate(value)); | 
 | 5760 |         } | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5761 |       } else { | 
 | 5762 |         DCHECK(destination.IsStackSlot()) << destination; | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5763 |         __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5764 |       } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5765 |     } else if (constant->IsFloatConstant()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5766 |       float fp_value = constant->AsFloatConstant()->GetValue(); | 
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5767 |       int32_t value = bit_cast<int32_t, float>(fp_value); | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5768 |       Immediate imm(value); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5769 |       if (destination.IsFpuRegister()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5770 |         XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); | 
 | 5771 |         if (value == 0) { | 
 | 5772 |           // Easy handling of 0.0. | 
 | 5773 |           __ xorps(dest, dest); | 
 | 5774 |         } else { | 
 | 5775 |           ScratchRegisterScope ensure_scratch( | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5776 |               this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); | 
 | 5777 |           Register temp = static_cast<Register>(ensure_scratch.GetRegister()); | 
 | 5778 |           __ movl(temp, Immediate(value)); | 
 | 5779 |           __ movd(dest, temp); | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5780 |         } | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5781 |       } else { | 
 | 5782 |         DCHECK(destination.IsStackSlot()) << destination; | 
 | 5783 |         __ movl(Address(ESP, destination.GetStackIndex()), imm); | 
 | 5784 |       } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5785 |     } else if (constant->IsLongConstant()) { | 
 | 5786 |       int64_t value = constant->AsLongConstant()->GetValue(); | 
 | 5787 |       int32_t low_value = Low32Bits(value); | 
 | 5788 |       int32_t high_value = High32Bits(value); | 
 | 5789 |       Immediate low(low_value); | 
 | 5790 |       Immediate high(high_value); | 
 | 5791 |       if (destination.IsDoubleStackSlot()) { | 
 | 5792 |         __ movl(Address(ESP, destination.GetStackIndex()), low); | 
 | 5793 |         __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); | 
 | 5794 |       } else { | 
 | 5795 |         __ movl(destination.AsRegisterPairLow<Register>(), low); | 
 | 5796 |         __ movl(destination.AsRegisterPairHigh<Register>(), high); | 
 | 5797 |       } | 
 | 5798 |     } else { | 
 | 5799 |       DCHECK(constant->IsDoubleConstant()); | 
 | 5800 |       double dbl_value = constant->AsDoubleConstant()->GetValue(); | 
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5801 |       int64_t value = bit_cast<int64_t, double>(dbl_value); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5802 |       int32_t low_value = Low32Bits(value); | 
 | 5803 |       int32_t high_value = High32Bits(value); | 
 | 5804 |       Immediate low(low_value); | 
 | 5805 |       Immediate high(high_value); | 
 | 5806 |       if (destination.IsFpuRegister()) { | 
 | 5807 |         XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); | 
 | 5808 |         if (value == 0) { | 
 | 5809 |           // Easy handling of 0.0. | 
 | 5810 |           __ xorpd(dest, dest); | 
 | 5811 |         } else { | 
 | 5812 |           __ pushl(high); | 
 | 5813 |           __ pushl(low); | 
 | 5814 |           __ movsd(dest, Address(ESP, 0)); | 
 | 5815 |           __ addl(ESP, Immediate(8)); | 
 | 5816 |         } | 
 | 5817 |       } else { | 
 | 5818 |         DCHECK(destination.IsDoubleStackSlot()) << destination; | 
 | 5819 |         __ movl(Address(ESP, destination.GetStackIndex()), low); | 
 | 5820 |         __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); | 
 | 5821 |       } | 
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5822 |     } | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5823 |   } else { | 
| Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5824 |     LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5825 |   } | 
 | 5826 | } | 
 | 5827 |  | 
| Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5828 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5829 |   Register suggested_scratch = reg == EAX ? EBX : EAX; | 
 | 5830 |   ScratchRegisterScope ensure_scratch( | 
 | 5831 |       this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); | 
 | 5832 |  | 
 | 5833 |   int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; | 
 | 5834 |   __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); | 
 | 5835 |   __ movl(Address(ESP, mem + stack_offset), reg); | 
 | 5836 |   __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5837 | } | 
 | 5838 |  | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5839 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5840 |   ScratchRegisterScope ensure_scratch( | 
 | 5841 |       this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); | 
 | 5842 |  | 
 | 5843 |   Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); | 
 | 5844 |   int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; | 
 | 5845 |   __ movl(temp_reg, Address(ESP, mem + stack_offset)); | 
 | 5846 |   __ movss(Address(ESP, mem + stack_offset), reg); | 
 | 5847 |   __ movd(reg, temp_reg); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5848 | } | 
 | 5849 |  | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5850 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5851 |   ScratchRegisterScope ensure_scratch1( | 
 | 5852 |       this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); | 
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5853 |  | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5854 |   Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; | 
 | 5855 |   ScratchRegisterScope ensure_scratch2( | 
 | 5856 |       this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); | 
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5857 |  | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5858 |   int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; | 
 | 5859 |   stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; | 
 | 5860 |   __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); | 
 | 5861 |   __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); | 
 | 5862 |   __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); | 
 | 5863 |   __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5864 | } | 
 | 5865 |  | 
 | 5866 | void ParallelMoveResolverX86::EmitSwap(size_t index) { | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5867 |   MoveOperands* move = moves_[index]; | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5868 |   Location source = move->GetSource(); | 
 | 5869 |   Location destination = move->GetDestination(); | 
 | 5870 |  | 
 | 5871 |   if (source.IsRegister() && destination.IsRegister()) { | 
| Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5872 |     // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. | 
 | 5873 |     DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
 | 5874 |     __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
 | 5875 |     __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); | 
 | 5876 |     __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5877 |   } else if (source.IsRegister() && destination.IsStackSlot()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5878 |     Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5879 |   } else if (source.IsStackSlot() && destination.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5880 |     Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5881 |   } else if (source.IsStackSlot() && destination.IsStackSlot()) { | 
 | 5882 |     Exchange(destination.GetStackIndex(), source.GetStackIndex()); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5883 |   } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { | 
 | 5884 |     // Use XOR Swap algorithm to avoid a temporary. | 
 | 5885 |     DCHECK_NE(source.reg(), destination.reg()); | 
 | 5886 |     __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
 | 5887 |     __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); | 
 | 5888 |     __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
 | 5889 |   } else if (source.IsFpuRegister() && destination.IsStackSlot()) { | 
 | 5890 |     Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); | 
 | 5891 |   } else if (destination.IsFpuRegister() && source.IsStackSlot()) { | 
 | 5892 |     Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5893 |   } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { | 
 | 5894 |     // Take advantage of the 16 bytes in the XMM register. | 
 | 5895 |     XmmRegister reg = source.AsFpuRegister<XmmRegister>(); | 
 | 5896 |     Address stack(ESP, destination.GetStackIndex()); | 
 | 5897 |     // Load the double into the high doubleword. | 
 | 5898 |     __ movhpd(reg, stack); | 
 | 5899 |  | 
 | 5900 |     // Store the low double into the destination. | 
 | 5901 |     __ movsd(stack, reg); | 
 | 5902 |  | 
 | 5903 |     // Move the high double to the low double. | 
 | 5904 |     __ psrldq(reg, Immediate(8)); | 
 | 5905 |   } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { | 
 | 5906 |     // Take advantage of the 16 bytes in the XMM register. | 
 | 5907 |     XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); | 
 | 5908 |     Address stack(ESP, source.GetStackIndex()); | 
 | 5909 |     // Load the double into the high doubleword. | 
 | 5910 |     __ movhpd(reg, stack); | 
 | 5911 |  | 
 | 5912 |     // Store the low double into the destination. | 
 | 5913 |     __ movsd(stack, reg); | 
 | 5914 |  | 
 | 5915 |     // Move the high double to the low double. | 
 | 5916 |     __ psrldq(reg, Immediate(8)); | 
 | 5917 |   } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { | 
 | 5918 |     Exchange(destination.GetStackIndex(), source.GetStackIndex()); | 
 | 5919 |     Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5920 |   } else { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5921 |     LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5922 |   } | 
 | 5923 | } | 
 | 5924 |  | 
 | 5925 | void ParallelMoveResolverX86::SpillScratch(int reg) { | 
 | 5926 |   __ pushl(static_cast<Register>(reg)); | 
 | 5927 | } | 
 | 5928 |  | 
 | 5929 | void ParallelMoveResolverX86::RestoreScratch(int reg) { | 
 | 5930 |   __ popl(static_cast<Register>(reg)); | 
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5931 | } | 
 | 5932 |  | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5933 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { | 
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5934 |   InvokeRuntimeCallingConvention calling_convention; | 
 | 5935 |   CodeGenerator::CreateLoadClassLocationSummary( | 
 | 5936 |       cls, | 
 | 5937 |       Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5938 |       Location::RegisterLocation(EAX), | 
 | 5939 |       /* code_generator_supports_read_barrier */ true); | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5940 | } | 
 | 5941 |  | 
 | 5942 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5943 |   LocationSummary* locations = cls->GetLocations(); | 
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5944 |   if (cls->NeedsAccessCheck()) { | 
 | 5945 |     codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); | 
 | 5946 |     codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), | 
 | 5947 |                             cls, | 
 | 5948 |                             cls->GetDexPc(), | 
 | 5949 |                             nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5950 |     CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); | 
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5951 |     return; | 
 | 5952 |   } | 
 | 5953 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5954 |   Location out_loc = locations->Out(); | 
 | 5955 |   Register out = out_loc.AsRegister<Register>(); | 
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5956 |   Register current_method = locations->InAt(0).AsRegister<Register>(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5957 |  | 
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5958 |   if (cls->IsReferrersClass()) { | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5959 |     DCHECK(!cls->CanCallRuntime()); | 
 | 5960 |     DCHECK(!cls->MustGenerateClinitCheck()); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5961 |     // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ | 
 | 5962 |     GenerateGcRootFieldLoad( | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5963 |         cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5964 |   } else { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5965 |     // /* GcRoot<mirror::Class>[] */ out = | 
 | 5966 |     //        current_method.ptr_sized_fields_->dex_cache_resolved_types_ | 
 | 5967 |     __ movl(out, Address(current_method, | 
 | 5968 |                          ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5969 |     // /* GcRoot<mirror::Class> */ out = out[type_index] | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5970 |     GenerateGcRootFieldLoad( | 
 | 5971 |         cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5972 |  | 
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5973 |     if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { | 
 | 5974 |       DCHECK(cls->CanCallRuntime()); | 
 | 5975 |       SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( | 
 | 5976 |           cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); | 
 | 5977 |       codegen_->AddSlowPath(slow_path); | 
 | 5978 |  | 
 | 5979 |       if (!cls->IsInDexCache()) { | 
 | 5980 |         __ testl(out, out); | 
 | 5981 |         __ j(kEqual, slow_path->GetEntryLabel()); | 
 | 5982 |       } | 
 | 5983 |  | 
 | 5984 |       if (cls->MustGenerateClinitCheck()) { | 
 | 5985 |         GenerateClassInitializationCheck(slow_path, out); | 
 | 5986 |       } else { | 
 | 5987 |         __ Bind(slow_path->GetExitLabel()); | 
 | 5988 |       } | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5989 |     } | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5990 |   } | 
 | 5991 | } | 
 | 5992 |  | 
 | 5993 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { | 
 | 5994 |   LocationSummary* locations = | 
 | 5995 |       new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); | 
 | 5996 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 5997 |   if (check->HasUses()) { | 
 | 5998 |     locations->SetOut(Location::SameAsFirstInput()); | 
 | 5999 |   } | 
 | 6000 | } | 
 | 6001 |  | 
 | 6002 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6003 |   // We assume the class to not be null. | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6004 |   SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6005 |       check->GetLoadClass(), check, check->GetDexPc(), true); | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6006 |   codegen_->AddSlowPath(slow_path); | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6007 |   GenerateClassInitializationCheck(slow_path, | 
 | 6008 |                                    check->GetLocations()->InAt(0).AsRegister<Register>()); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6009 | } | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6010 |  | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6011 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6012 |     SlowPathCode* slow_path, Register class_reg) { | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6013 |   __ cmpl(Address(class_reg,  mirror::Class::StatusOffset().Int32Value()), | 
 | 6014 |           Immediate(mirror::Class::kStatusInitialized)); | 
 | 6015 |   __ j(kLess, slow_path->GetEntryLabel()); | 
 | 6016 |   __ Bind(slow_path->GetExitLabel()); | 
 | 6017 |   // No need for memory fence, thanks to the X86 memory model. | 
 | 6018 | } | 
 | 6019 |  | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6020 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( | 
 | 6021 |     HLoadString::LoadKind desired_string_load_kind) { | 
 | 6022 |   if (kEmitCompilerReadBarrier) { | 
 | 6023 |     switch (desired_string_load_kind) { | 
 | 6024 |       case HLoadString::LoadKind::kBootImageLinkTimeAddress: | 
 | 6025 |       case HLoadString::LoadKind::kBootImageLinkTimePcRelative: | 
 | 6026 |       case HLoadString::LoadKind::kBootImageAddress: | 
 | 6027 |         // TODO: Implement for read barrier. | 
 | 6028 |         return HLoadString::LoadKind::kDexCacheViaMethod; | 
 | 6029 |       default: | 
 | 6030 |         break; | 
 | 6031 |     } | 
 | 6032 |   } | 
 | 6033 |   switch (desired_string_load_kind) { | 
 | 6034 |     case HLoadString::LoadKind::kBootImageLinkTimeAddress: | 
 | 6035 |       DCHECK(!GetCompilerOptions().GetCompilePic()); | 
 | 6036 |       break; | 
 | 6037 |     case HLoadString::LoadKind::kBootImageLinkTimePcRelative: | 
 | 6038 |       DCHECK(GetCompilerOptions().GetCompilePic()); | 
 | 6039 |       FALLTHROUGH_INTENDED; | 
 | 6040 |     case HLoadString::LoadKind::kDexCachePcRelative: | 
 | 6041 |       DCHECK(!Runtime::Current()->UseJit());  // Note: boot image is also non-JIT. | 
 | 6042 |       // We disable pc-relative load when there is an irreducible loop, as the optimization | 
 | 6043 |       // is incompatible with it. | 
 | 6044 |       // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods | 
 | 6045 |       // with irreducible loops. | 
 | 6046 |       if (GetGraph()->HasIrreducibleLoops()) { | 
 | 6047 |         return HLoadString::LoadKind::kDexCacheViaMethod; | 
 | 6048 |       } | 
 | 6049 |       break; | 
 | 6050 |     case HLoadString::LoadKind::kBootImageAddress: | 
 | 6051 |       break; | 
 | 6052 |     case HLoadString::LoadKind::kDexCacheAddress: | 
 | 6053 |       DCHECK(Runtime::Current()->UseJit()); | 
 | 6054 |       break; | 
 | 6055 |     case HLoadString::LoadKind::kDexCacheViaMethod: | 
 | 6056 |       break; | 
 | 6057 |   } | 
 | 6058 |   return desired_string_load_kind; | 
 | 6059 | } | 
 | 6060 |  | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6061 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6062 |   LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) | 
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6063 |       ? LocationSummary::kCallOnSlowPath | 
 | 6064 |       : LocationSummary::kNoCall; | 
 | 6065 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6066 |   HLoadString::LoadKind load_kind = load->GetLoadKind(); | 
 | 6067 |   if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || | 
 | 6068 |       load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || | 
 | 6069 |       load_kind == HLoadString::LoadKind::kDexCachePcRelative) { | 
 | 6070 |     locations->SetInAt(0, Location::RequiresRegister()); | 
 | 6071 |   } | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6072 |   locations->SetOut(Location::RequiresRegister()); | 
 | 6073 | } | 
 | 6074 |  | 
 | 6075 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { | 
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6076 |   LocationSummary* locations = load->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6077 |   Location out_loc = locations->Out(); | 
 | 6078 |   Register out = out_loc.AsRegister<Register>(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6079 |  | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6080 |   switch (load->GetLoadKind()) { | 
 | 6081 |     case HLoadString::LoadKind::kBootImageLinkTimeAddress: { | 
 | 6082 |       DCHECK(!kEmitCompilerReadBarrier); | 
 | 6083 |       __ movl(out, Immediate(/* placeholder */ 0)); | 
 | 6084 |       codegen_->RecordStringPatch(load); | 
 | 6085 |       return;  // No dex cache slow path. | 
 | 6086 |     } | 
 | 6087 |     case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { | 
 | 6088 |       DCHECK(!kEmitCompilerReadBarrier); | 
 | 6089 |       Register method_address = locations->InAt(0).AsRegister<Register>(); | 
 | 6090 |       __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); | 
 | 6091 |       codegen_->RecordStringPatch(load); | 
 | 6092 |       return;  // No dex cache slow path. | 
 | 6093 |     } | 
 | 6094 |     case HLoadString::LoadKind::kBootImageAddress: { | 
 | 6095 |       DCHECK(!kEmitCompilerReadBarrier); | 
 | 6096 |       DCHECK_NE(load->GetAddress(), 0u); | 
 | 6097 |       uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); | 
 | 6098 |       __ movl(out, Immediate(address)); | 
 | 6099 |       codegen_->RecordSimplePatch(); | 
 | 6100 |       return;  // No dex cache slow path. | 
 | 6101 |     } | 
 | 6102 |     case HLoadString::LoadKind::kDexCacheAddress: { | 
 | 6103 |       DCHECK_NE(load->GetAddress(), 0u); | 
 | 6104 |       uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); | 
 | 6105 |       GenerateGcRootFieldLoad(load, out_loc, Address::Absolute(address)); | 
 | 6106 |       break; | 
 | 6107 |     } | 
 | 6108 |     case HLoadString::LoadKind::kDexCachePcRelative: { | 
 | 6109 |       Register base_reg = locations->InAt(0).AsRegister<Register>(); | 
 | 6110 |       uint32_t offset = load->GetDexCacheElementOffset(); | 
 | 6111 |       Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(load->GetDexFile(), offset); | 
 | 6112 |       GenerateGcRootFieldLoad( | 
 | 6113 |           load, out_loc, Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), fixup_label); | 
 | 6114 |       break; | 
 | 6115 |     } | 
 | 6116 |     case HLoadString::LoadKind::kDexCacheViaMethod: { | 
 | 6117 |       Register current_method = locations->InAt(0).AsRegister<Register>(); | 
 | 6118 |  | 
 | 6119 |       // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ | 
 | 6120 |       GenerateGcRootFieldLoad( | 
 | 6121 |           load, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); | 
 | 6122 |  | 
 | 6123 |       // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ | 
 | 6124 |       __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); | 
 | 6125 |       // /* GcRoot<mirror::String> */ out = out[string_index] | 
 | 6126 |       GenerateGcRootFieldLoad( | 
 | 6127 |           load, out_loc, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); | 
 | 6128 |       break; | 
 | 6129 |     } | 
 | 6130 |     default: | 
 | 6131 |       LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); | 
 | 6132 |       UNREACHABLE(); | 
 | 6133 |   } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6134 |  | 
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6135 |   if (!load->IsInDexCache()) { | 
 | 6136 |     SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); | 
 | 6137 |     codegen_->AddSlowPath(slow_path); | 
 | 6138 |     __ testl(out, out); | 
 | 6139 |     __ j(kEqual, slow_path->GetEntryLabel()); | 
 | 6140 |     __ Bind(slow_path->GetExitLabel()); | 
 | 6141 |   } | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6142 | } | 
 | 6143 |  | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6144 | static Address GetExceptionTlsAddress() { | 
 | 6145 |   return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); | 
 | 6146 | } | 
 | 6147 |  | 
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6148 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { | 
 | 6149 |   LocationSummary* locations = | 
 | 6150 |       new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); | 
 | 6151 |   locations->SetOut(Location::RequiresRegister()); | 
 | 6152 | } | 
 | 6153 |  | 
 | 6154 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6155 |   __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); | 
 | 6156 | } | 
 | 6157 |  | 
 | 6158 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { | 
 | 6159 |   new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); | 
 | 6160 | } | 
 | 6161 |  | 
 | 6162 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { | 
 | 6163 |   __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); | 
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6164 | } | 
 | 6165 |  | 
 | 6166 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { | 
 | 6167 |   LocationSummary* locations = | 
 | 6168 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
 | 6169 |   InvokeRuntimeCallingConvention calling_convention; | 
 | 6170 |   locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
 | 6171 | } | 
 | 6172 |  | 
 | 6173 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6174 |   codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), | 
 | 6175 |                           instruction, | 
 | 6176 |                           instruction->GetDexPc(), | 
 | 6177 |                           nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6178 |   CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); | 
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6179 | } | 
 | 6180 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6181 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { | 
 | 6182 |   return kEmitCompilerReadBarrier && | 
 | 6183 |       (kUseBakerReadBarrier || | 
 | 6184 |        type_check_kind == TypeCheckKind::kAbstractClassCheck || | 
 | 6185 |        type_check_kind == TypeCheckKind::kClassHierarchyCheck || | 
 | 6186 |        type_check_kind == TypeCheckKind::kArrayObjectCheck); | 
 | 6187 | } | 
 | 6188 |  | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6189 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6190 |   LocationSummary::CallKind call_kind = LocationSummary::kNoCall; | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6191 |   TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); | 
 | 6192 |   switch (type_check_kind) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6193 |     case TypeCheckKind::kExactCheck: | 
 | 6194 |     case TypeCheckKind::kAbstractClassCheck: | 
 | 6195 |     case TypeCheckKind::kClassHierarchyCheck: | 
 | 6196 |     case TypeCheckKind::kArrayObjectCheck: | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6197 |       call_kind = | 
 | 6198 |           kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6199 |       break; | 
 | 6200 |     case TypeCheckKind::kArrayCheck: | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6201 |     case TypeCheckKind::kUnresolvedCheck: | 
 | 6202 |     case TypeCheckKind::kInterfaceCheck: | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6203 |       call_kind = LocationSummary::kCallOnSlowPath; | 
 | 6204 |       break; | 
 | 6205 |   } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6206 |  | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6207 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6208 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 6209 |   locations->SetInAt(1, Location::Any()); | 
 | 6210 |   // Note that TypeCheckSlowPathX86 uses this "out" register too. | 
 | 6211 |   locations->SetOut(Location::RequiresRegister()); | 
 | 6212 |   // When read barriers are enabled, we need a temporary register for | 
 | 6213 |   // some cases. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6214 |   if (TypeCheckNeedsATemporary(type_check_kind)) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6215 |     locations->AddTemp(Location::RequiresRegister()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6216 |   } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6217 | } | 
 | 6218 |  | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6219 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6220 |   TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6221 |   LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6222 |   Location obj_loc = locations->InAt(0); | 
 | 6223 |   Register obj = obj_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6224 |   Location cls = locations->InAt(1); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6225 |   Location out_loc = locations->Out(); | 
 | 6226 |   Register out = out_loc.AsRegister<Register>(); | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6227 |   Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6228 |       locations->GetTemp(0) : | 
 | 6229 |       Location::NoLocation(); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6230 |   uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6231 |   uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); | 
 | 6232 |   uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); | 
 | 6233 |   uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6234 |   SlowPathCode* slow_path = nullptr; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6235 |   NearLabel done, zero; | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6236 |  | 
 | 6237 |   // Return 0 if `obj` is null. | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6238 |   // Avoid null check if we know obj is not null. | 
 | 6239 |   if (instruction->MustDoNullCheck()) { | 
 | 6240 |     __ testl(obj, obj); | 
 | 6241 |     __ j(kEqual, &zero); | 
 | 6242 |   } | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6243 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6244 |   // /* HeapReference<Class> */ out = obj->klass_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6245 |   GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6246 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6247 |   switch (type_check_kind) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6248 |     case TypeCheckKind::kExactCheck: { | 
 | 6249 |       if (cls.IsRegister()) { | 
 | 6250 |         __ cmpl(out, cls.AsRegister<Register>()); | 
 | 6251 |       } else { | 
 | 6252 |         DCHECK(cls.IsStackSlot()) << cls; | 
 | 6253 |         __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
 | 6254 |       } | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6255 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6256 |       // Classes must be equal for the instanceof to succeed. | 
 | 6257 |       __ j(kNotEqual, &zero); | 
 | 6258 |       __ movl(out, Immediate(1)); | 
 | 6259 |       __ jmp(&done); | 
 | 6260 |       break; | 
 | 6261 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6262 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6263 |     case TypeCheckKind::kAbstractClassCheck: { | 
 | 6264 |       // If the class is abstract, we eagerly fetch the super class of the | 
 | 6265 |       // object to avoid doing a comparison we know will fail. | 
 | 6266 |       NearLabel loop; | 
 | 6267 |       __ Bind(&loop); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6268 |       // /* HeapReference<Class> */ out = out->super_class_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6269 |       GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6270 |       __ testl(out, out); | 
 | 6271 |       // If `out` is null, we use it for the result, and jump to `done`. | 
 | 6272 |       __ j(kEqual, &done); | 
 | 6273 |       if (cls.IsRegister()) { | 
 | 6274 |         __ cmpl(out, cls.AsRegister<Register>()); | 
 | 6275 |       } else { | 
 | 6276 |         DCHECK(cls.IsStackSlot()) << cls; | 
 | 6277 |         __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
 | 6278 |       } | 
 | 6279 |       __ j(kNotEqual, &loop); | 
 | 6280 |       __ movl(out, Immediate(1)); | 
 | 6281 |       if (zero.IsLinked()) { | 
 | 6282 |         __ jmp(&done); | 
 | 6283 |       } | 
 | 6284 |       break; | 
 | 6285 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6286 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6287 |     case TypeCheckKind::kClassHierarchyCheck: { | 
 | 6288 |       // Walk over the class hierarchy to find a match. | 
 | 6289 |       NearLabel loop, success; | 
 | 6290 |       __ Bind(&loop); | 
 | 6291 |       if (cls.IsRegister()) { | 
 | 6292 |         __ cmpl(out, cls.AsRegister<Register>()); | 
 | 6293 |       } else { | 
 | 6294 |         DCHECK(cls.IsStackSlot()) << cls; | 
 | 6295 |         __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
 | 6296 |       } | 
 | 6297 |       __ j(kEqual, &success); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6298 |       // /* HeapReference<Class> */ out = out->super_class_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6299 |       GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6300 |       __ testl(out, out); | 
 | 6301 |       __ j(kNotEqual, &loop); | 
 | 6302 |       // If `out` is null, we use it for the result, and jump to `done`. | 
 | 6303 |       __ jmp(&done); | 
 | 6304 |       __ Bind(&success); | 
 | 6305 |       __ movl(out, Immediate(1)); | 
 | 6306 |       if (zero.IsLinked()) { | 
 | 6307 |         __ jmp(&done); | 
 | 6308 |       } | 
 | 6309 |       break; | 
 | 6310 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6311 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6312 |     case TypeCheckKind::kArrayObjectCheck: { | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6313 |       // Do an exact check. | 
 | 6314 |       NearLabel exact_check; | 
 | 6315 |       if (cls.IsRegister()) { | 
 | 6316 |         __ cmpl(out, cls.AsRegister<Register>()); | 
 | 6317 |       } else { | 
 | 6318 |         DCHECK(cls.IsStackSlot()) << cls; | 
 | 6319 |         __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
 | 6320 |       } | 
 | 6321 |       __ j(kEqual, &exact_check); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6322 |       // Otherwise, we need to check that the object's class is a non-primitive array. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6323 |       // /* HeapReference<Class> */ out = out->component_type_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6324 |       GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6325 |       __ testl(out, out); | 
 | 6326 |       // If `out` is null, we use it for the result, and jump to `done`. | 
 | 6327 |       __ j(kEqual, &done); | 
 | 6328 |       __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); | 
 | 6329 |       __ j(kNotEqual, &zero); | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6330 |       __ Bind(&exact_check); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6331 |       __ movl(out, Immediate(1)); | 
 | 6332 |       __ jmp(&done); | 
 | 6333 |       break; | 
 | 6334 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6335 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6336 |     case TypeCheckKind::kArrayCheck: { | 
 | 6337 |       if (cls.IsRegister()) { | 
 | 6338 |         __ cmpl(out, cls.AsRegister<Register>()); | 
 | 6339 |       } else { | 
 | 6340 |         DCHECK(cls.IsStackSlot()) << cls; | 
 | 6341 |         __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
 | 6342 |       } | 
 | 6343 |       DCHECK(locations->OnlyCallsOnSlowPath()); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6344 |       slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, | 
 | 6345 |                                                                     /* is_fatal */ false); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6346 |       codegen_->AddSlowPath(slow_path); | 
 | 6347 |       __ j(kNotEqual, slow_path->GetEntryLabel()); | 
 | 6348 |       __ movl(out, Immediate(1)); | 
 | 6349 |       if (zero.IsLinked()) { | 
 | 6350 |         __ jmp(&done); | 
 | 6351 |       } | 
 | 6352 |       break; | 
 | 6353 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6354 |  | 
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6355 |     case TypeCheckKind::kUnresolvedCheck: | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6356 |     case TypeCheckKind::kInterfaceCheck: { | 
 | 6357 |       // Note that we indeed only call on slow path, but we always go | 
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6358 |       // into the slow path for the unresolved and interface check | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6359 |       // cases. | 
 | 6360 |       // | 
 | 6361 |       // We cannot directly call the InstanceofNonTrivial runtime | 
 | 6362 |       // entry point without resorting to a type checking slow path | 
 | 6363 |       // here (i.e. by calling InvokeRuntime directly), as it would | 
 | 6364 |       // require to assign fixed registers for the inputs of this | 
 | 6365 |       // HInstanceOf instruction (following the runtime calling | 
 | 6366 |       // convention), which might be cluttered by the potential first | 
 | 6367 |       // read barrier emission at the beginning of this method. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6368 |       // | 
 | 6369 |       // TODO: Introduce a new runtime entry point taking the object | 
 | 6370 |       // to test (instead of its class) as argument, and let it deal | 
 | 6371 |       // with the read barrier issues. This will let us refactor this | 
 | 6372 |       // case of the `switch` code as it was previously (with a direct | 
 | 6373 |       // call to the runtime not using a type checking slow path). | 
 | 6374 |       // This should also be beneficial for the other cases above. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6375 |       DCHECK(locations->OnlyCallsOnSlowPath()); | 
 | 6376 |       slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, | 
 | 6377 |                                                                     /* is_fatal */ false); | 
 | 6378 |       codegen_->AddSlowPath(slow_path); | 
 | 6379 |       __ jmp(slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6380 |       if (zero.IsLinked()) { | 
 | 6381 |         __ jmp(&done); | 
 | 6382 |       } | 
 | 6383 |       break; | 
 | 6384 |     } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6385 |   } | 
 | 6386 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6387 |   if (zero.IsLinked()) { | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6388 |     __ Bind(&zero); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6389 |     __ xorl(out, out); | 
 | 6390 |   } | 
 | 6391 |  | 
 | 6392 |   if (done.IsLinked()) { | 
 | 6393 |     __ Bind(&done); | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6394 |   } | 
 | 6395 |  | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6396 |   if (slow_path != nullptr) { | 
 | 6397 |     __ Bind(slow_path->GetExitLabel()); | 
 | 6398 |   } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6399 | } | 
 | 6400 |  | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6401 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6402 |   LocationSummary::CallKind call_kind = LocationSummary::kNoCall; | 
 | 6403 |   bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6404 |   TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); | 
 | 6405 |   switch (type_check_kind) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6406 |     case TypeCheckKind::kExactCheck: | 
 | 6407 |     case TypeCheckKind::kAbstractClassCheck: | 
 | 6408 |     case TypeCheckKind::kClassHierarchyCheck: | 
 | 6409 |     case TypeCheckKind::kArrayObjectCheck: | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6410 |       call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? | 
 | 6411 |           LocationSummary::kCallOnSlowPath : | 
 | 6412 |           LocationSummary::kNoCall;  // In fact, call on a fatal (non-returning) slow path. | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6413 |       break; | 
 | 6414 |     case TypeCheckKind::kArrayCheck: | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6415 |     case TypeCheckKind::kUnresolvedCheck: | 
 | 6416 |     case TypeCheckKind::kInterfaceCheck: | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6417 |       call_kind = LocationSummary::kCallOnSlowPath; | 
 | 6418 |       break; | 
 | 6419 |   } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6420 |   LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); | 
 | 6421 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 6422 |   locations->SetInAt(1, Location::Any()); | 
 | 6423 |   // Note that TypeCheckSlowPathX86 uses this "temp" register too. | 
 | 6424 |   locations->AddTemp(Location::RequiresRegister()); | 
 | 6425 |   // When read barriers are enabled, we need an additional temporary | 
 | 6426 |   // register for some cases. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6427 |   if (TypeCheckNeedsATemporary(type_check_kind)) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6428 |     locations->AddTemp(Location::RequiresRegister()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6429 |   } | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6430 | } | 
 | 6431 |  | 
 | 6432 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6433 |   TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6434 |   LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6435 |   Location obj_loc = locations->InAt(0); | 
 | 6436 |   Register obj = obj_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6437 |   Location cls = locations->InAt(1); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6438 |   Location temp_loc = locations->GetTemp(0); | 
 | 6439 |   Register temp = temp_loc.AsRegister<Register>(); | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6440 |   Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6441 |       locations->GetTemp(1) : | 
 | 6442 |       Location::NoLocation(); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6443 |   uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
 | 6444 |   uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); | 
 | 6445 |   uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); | 
 | 6446 |   uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6447 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6448 |   bool is_type_check_slow_path_fatal = | 
 | 6449 |       (type_check_kind == TypeCheckKind::kExactCheck || | 
 | 6450 |        type_check_kind == TypeCheckKind::kAbstractClassCheck || | 
 | 6451 |        type_check_kind == TypeCheckKind::kClassHierarchyCheck || | 
 | 6452 |        type_check_kind == TypeCheckKind::kArrayObjectCheck) && | 
 | 6453 |       !instruction->CanThrowIntoCatchBlock(); | 
 | 6454 |   SlowPathCode* type_check_slow_path = | 
 | 6455 |       new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, | 
 | 6456 |                                                         is_type_check_slow_path_fatal); | 
 | 6457 |   codegen_->AddSlowPath(type_check_slow_path); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6458 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6459 |   NearLabel done; | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6460 |   // Avoid null check if we know obj is not null. | 
 | 6461 |   if (instruction->MustDoNullCheck()) { | 
 | 6462 |     __ testl(obj, obj); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6463 |     __ j(kEqual, &done); | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6464 |   } | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6465 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6466 |   // /* HeapReference<Class> */ temp = obj->klass_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6467 |   GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6468 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6469 |   switch (type_check_kind) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6470 |     case TypeCheckKind::kExactCheck: | 
 | 6471 |     case TypeCheckKind::kArrayCheck: { | 
 | 6472 |       if (cls.IsRegister()) { | 
 | 6473 |         __ cmpl(temp, cls.AsRegister<Register>()); | 
 | 6474 |       } else { | 
 | 6475 |         DCHECK(cls.IsStackSlot()) << cls; | 
 | 6476 |         __ cmpl(temp, Address(ESP, cls.GetStackIndex())); | 
 | 6477 |       } | 
 | 6478 |       // Jump to slow path for throwing the exception or doing a | 
 | 6479 |       // more involved array check. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6480 |       __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6481 |       break; | 
 | 6482 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6483 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6484 |     case TypeCheckKind::kAbstractClassCheck: { | 
 | 6485 |       // If the class is abstract, we eagerly fetch the super class of the | 
 | 6486 |       // object to avoid doing a comparison we know will fail. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6487 |       NearLabel loop, compare_classes; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6488 |       __ Bind(&loop); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6489 |       // /* HeapReference<Class> */ temp = temp->super_class_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6490 |       GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6491 |  | 
 | 6492 |       // If the class reference currently in `temp` is not null, jump | 
 | 6493 |       // to the `compare_classes` label to compare it with the checked | 
 | 6494 |       // class. | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6495 |       __ testl(temp, temp); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6496 |       __ j(kNotEqual, &compare_classes); | 
 | 6497 |       // Otherwise, jump to the slow path to throw the exception. | 
 | 6498 |       // | 
 | 6499 |       // But before, move back the object's class into `temp` before | 
 | 6500 |       // going into the slow path, as it has been overwritten in the | 
 | 6501 |       // meantime. | 
 | 6502 |       // /* HeapReference<Class> */ temp = obj->klass_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6503 |       GenerateReferenceLoadTwoRegisters( | 
 | 6504 |           instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6505 |       __ jmp(type_check_slow_path->GetEntryLabel()); | 
 | 6506 |  | 
 | 6507 |       __ Bind(&compare_classes); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6508 |       if (cls.IsRegister()) { | 
 | 6509 |         __ cmpl(temp, cls.AsRegister<Register>()); | 
 | 6510 |       } else { | 
 | 6511 |         DCHECK(cls.IsStackSlot()) << cls; | 
 | 6512 |         __ cmpl(temp, Address(ESP, cls.GetStackIndex())); | 
 | 6513 |       } | 
 | 6514 |       __ j(kNotEqual, &loop); | 
 | 6515 |       break; | 
 | 6516 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6517 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6518 |     case TypeCheckKind::kClassHierarchyCheck: { | 
 | 6519 |       // Walk over the class hierarchy to find a match. | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6520 |       NearLabel loop; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6521 |       __ Bind(&loop); | 
 | 6522 |       if (cls.IsRegister()) { | 
 | 6523 |         __ cmpl(temp, cls.AsRegister<Register>()); | 
 | 6524 |       } else { | 
 | 6525 |         DCHECK(cls.IsStackSlot()) << cls; | 
 | 6526 |         __ cmpl(temp, Address(ESP, cls.GetStackIndex())); | 
 | 6527 |       } | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6528 |       __ j(kEqual, &done); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6529 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6530 |       // /* HeapReference<Class> */ temp = temp->super_class_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6531 |       GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6532 |  | 
 | 6533 |       // If the class reference currently in `temp` is not null, jump | 
 | 6534 |       // back at the beginning of the loop. | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6535 |       __ testl(temp, temp); | 
 | 6536 |       __ j(kNotEqual, &loop); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6537 |       // Otherwise, jump to the slow path to throw the exception. | 
 | 6538 |       // | 
 | 6539 |       // But before, move back the object's class into `temp` before | 
 | 6540 |       // going into the slow path, as it has been overwritten in the | 
 | 6541 |       // meantime. | 
 | 6542 |       // /* HeapReference<Class> */ temp = obj->klass_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6543 |       GenerateReferenceLoadTwoRegisters( | 
 | 6544 |           instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6545 |       __ jmp(type_check_slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6546 |       break; | 
 | 6547 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6548 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6549 |     case TypeCheckKind::kArrayObjectCheck: { | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6550 |       // Do an exact check. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6551 |       NearLabel check_non_primitive_component_type; | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6552 |       if (cls.IsRegister()) { | 
 | 6553 |         __ cmpl(temp, cls.AsRegister<Register>()); | 
 | 6554 |       } else { | 
 | 6555 |         DCHECK(cls.IsStackSlot()) << cls; | 
 | 6556 |         __ cmpl(temp, Address(ESP, cls.GetStackIndex())); | 
 | 6557 |       } | 
 | 6558 |       __ j(kEqual, &done); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6559 |  | 
 | 6560 |       // Otherwise, we need to check that the object's class is a non-primitive array. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6561 |       // /* HeapReference<Class> */ temp = temp->component_type_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6562 |       GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6563 |  | 
 | 6564 |       // If the component type is not null (i.e. the object is indeed | 
 | 6565 |       // an array), jump to label `check_non_primitive_component_type` | 
 | 6566 |       // to further check that this component type is not a primitive | 
 | 6567 |       // type. | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6568 |       __ testl(temp, temp); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6569 |       __ j(kNotEqual, &check_non_primitive_component_type); | 
 | 6570 |       // Otherwise, jump to the slow path to throw the exception. | 
 | 6571 |       // | 
 | 6572 |       // But before, move back the object's class into `temp` before | 
 | 6573 |       // going into the slow path, as it has been overwritten in the | 
 | 6574 |       // meantime. | 
 | 6575 |       // /* HeapReference<Class> */ temp = obj->klass_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6576 |       GenerateReferenceLoadTwoRegisters( | 
 | 6577 |           instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6578 |       __ jmp(type_check_slow_path->GetEntryLabel()); | 
 | 6579 |  | 
 | 6580 |       __ Bind(&check_non_primitive_component_type); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6581 |       __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6582 |       __ j(kEqual, &done); | 
 | 6583 |       // Same comment as above regarding `temp` and the slow path. | 
 | 6584 |       // /* HeapReference<Class> */ temp = obj->klass_ | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6585 |       GenerateReferenceLoadTwoRegisters( | 
 | 6586 |           instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6587 |       __ jmp(type_check_slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6588 |       break; | 
 | 6589 |     } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6590 |  | 
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6591 |     case TypeCheckKind::kUnresolvedCheck: | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6592 |     case TypeCheckKind::kInterfaceCheck: | 
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6593 |       // We always go into the type check slow path for the unresolved | 
 | 6594 |       // and interface check cases. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6595 |       // | 
 | 6596 |       // We cannot directly call the CheckCast runtime entry point | 
 | 6597 |       // without resorting to a type checking slow path here (i.e. by | 
 | 6598 |       // calling InvokeRuntime directly), as it would require to | 
 | 6599 |       // assign fixed registers for the inputs of this HInstanceOf | 
 | 6600 |       // instruction (following the runtime calling convention), which | 
 | 6601 |       // might be cluttered by the potential first read barrier | 
 | 6602 |       // emission at the beginning of this method. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6603 |       // | 
 | 6604 |       // TODO: Introduce a new runtime entry point taking the object | 
 | 6605 |       // to test (instead of its class) as argument, and let it deal | 
 | 6606 |       // with the read barrier issues. This will let us refactor this | 
 | 6607 |       // case of the `switch` code as it was previously (with a direct | 
 | 6608 |       // call to the runtime not using a type checking slow path). | 
 | 6609 |       // This should also be beneficial for the other cases above. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6610 |       __ jmp(type_check_slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6611 |       break; | 
 | 6612 |   } | 
 | 6613 |   __ Bind(&done); | 
 | 6614 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6615 |   __ Bind(type_check_slow_path->GetExitLabel()); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6616 | } | 
 | 6617 |  | 
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6618 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { | 
 | 6619 |   LocationSummary* locations = | 
 | 6620 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); | 
 | 6621 |   InvokeRuntimeCallingConvention calling_convention; | 
 | 6622 |   locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
 | 6623 | } | 
 | 6624 |  | 
 | 6625 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6626 |   codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) | 
 | 6627 |                                                  : QUICK_ENTRY_POINT(pUnlockObject), | 
 | 6628 |                           instruction, | 
 | 6629 |                           instruction->GetDexPc(), | 
 | 6630 |                           nullptr); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6631 |   if (instruction->IsEnter()) { | 
 | 6632 |     CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); | 
 | 6633 |   } else { | 
 | 6634 |     CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); | 
 | 6635 |   } | 
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6636 | } | 
 | 6637 |  | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6638 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } | 
 | 6639 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } | 
 | 6640 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } | 
 | 6641 |  | 
 | 6642 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { | 
 | 6643 |   LocationSummary* locations = | 
 | 6644 |       new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); | 
 | 6645 |   DCHECK(instruction->GetResultType() == Primitive::kPrimInt | 
 | 6646 |          || instruction->GetResultType() == Primitive::kPrimLong); | 
 | 6647 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 6648 |   locations->SetInAt(1, Location::Any()); | 
 | 6649 |   locations->SetOut(Location::SameAsFirstInput()); | 
 | 6650 | } | 
 | 6651 |  | 
 | 6652 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { | 
 | 6653 |   HandleBitwiseOperation(instruction); | 
 | 6654 | } | 
 | 6655 |  | 
 | 6656 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { | 
 | 6657 |   HandleBitwiseOperation(instruction); | 
 | 6658 | } | 
 | 6659 |  | 
 | 6660 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { | 
 | 6661 |   HandleBitwiseOperation(instruction); | 
 | 6662 | } | 
 | 6663 |  | 
 | 6664 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { | 
 | 6665 |   LocationSummary* locations = instruction->GetLocations(); | 
 | 6666 |   Location first = locations->InAt(0); | 
 | 6667 |   Location second = locations->InAt(1); | 
 | 6668 |   DCHECK(first.Equals(locations->Out())); | 
 | 6669 |  | 
 | 6670 |   if (instruction->GetResultType() == Primitive::kPrimInt) { | 
 | 6671 |     if (second.IsRegister()) { | 
 | 6672 |       if (instruction->IsAnd()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6673 |         __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6674 |       } else if (instruction->IsOr()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6675 |         __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6676 |       } else { | 
 | 6677 |         DCHECK(instruction->IsXor()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6678 |         __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6679 |       } | 
 | 6680 |     } else if (second.IsConstant()) { | 
 | 6681 |       if (instruction->IsAnd()) { | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6682 |         __ andl(first.AsRegister<Register>(), | 
 | 6683 |                 Immediate(second.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6684 |       } else if (instruction->IsOr()) { | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6685 |         __ orl(first.AsRegister<Register>(), | 
 | 6686 |                Immediate(second.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6687 |       } else { | 
 | 6688 |         DCHECK(instruction->IsXor()); | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6689 |         __ xorl(first.AsRegister<Register>(), | 
 | 6690 |                 Immediate(second.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6691 |       } | 
 | 6692 |     } else { | 
 | 6693 |       if (instruction->IsAnd()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6694 |         __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6695 |       } else if (instruction->IsOr()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6696 |         __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6697 |       } else { | 
 | 6698 |         DCHECK(instruction->IsXor()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6699 |         __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6700 |       } | 
 | 6701 |     } | 
 | 6702 |   } else { | 
 | 6703 |     DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); | 
 | 6704 |     if (second.IsRegisterPair()) { | 
 | 6705 |       if (instruction->IsAnd()) { | 
 | 6706 |         __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
 | 6707 |         __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
 | 6708 |       } else if (instruction->IsOr()) { | 
 | 6709 |         __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
 | 6710 |         __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
 | 6711 |       } else { | 
 | 6712 |         DCHECK(instruction->IsXor()); | 
 | 6713 |         __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
 | 6714 |         __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
 | 6715 |       } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6716 |     } else if (second.IsDoubleStackSlot()) { | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6717 |       if (instruction->IsAnd()) { | 
 | 6718 |         __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
 | 6719 |         __ andl(first.AsRegisterPairHigh<Register>(), | 
 | 6720 |                 Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
 | 6721 |       } else if (instruction->IsOr()) { | 
 | 6722 |         __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
 | 6723 |         __ orl(first.AsRegisterPairHigh<Register>(), | 
 | 6724 |                 Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
 | 6725 |       } else { | 
 | 6726 |         DCHECK(instruction->IsXor()); | 
 | 6727 |         __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
 | 6728 |         __ xorl(first.AsRegisterPairHigh<Register>(), | 
 | 6729 |                 Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
 | 6730 |       } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6731 |     } else { | 
 | 6732 |       DCHECK(second.IsConstant()) << second; | 
 | 6733 |       int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6734 |       int32_t low_value = Low32Bits(value); | 
 | 6735 |       int32_t high_value = High32Bits(value); | 
 | 6736 |       Immediate low(low_value); | 
 | 6737 |       Immediate high(high_value); | 
 | 6738 |       Register first_low = first.AsRegisterPairLow<Register>(); | 
 | 6739 |       Register first_high = first.AsRegisterPairHigh<Register>(); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6740 |       if (instruction->IsAnd()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6741 |         if (low_value == 0) { | 
 | 6742 |           __ xorl(first_low, first_low); | 
 | 6743 |         } else if (low_value != -1) { | 
 | 6744 |           __ andl(first_low, low); | 
 | 6745 |         } | 
 | 6746 |         if (high_value == 0) { | 
 | 6747 |           __ xorl(first_high, first_high); | 
 | 6748 |         } else if (high_value != -1) { | 
 | 6749 |           __ andl(first_high, high); | 
 | 6750 |         } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6751 |       } else if (instruction->IsOr()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6752 |         if (low_value != 0) { | 
 | 6753 |           __ orl(first_low, low); | 
 | 6754 |         } | 
 | 6755 |         if (high_value != 0) { | 
 | 6756 |           __ orl(first_high, high); | 
 | 6757 |         } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6758 |       } else { | 
 | 6759 |         DCHECK(instruction->IsXor()); | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6760 |         if (low_value != 0) { | 
 | 6761 |           __ xorl(first_low, low); | 
 | 6762 |         } | 
 | 6763 |         if (high_value != 0) { | 
 | 6764 |           __ xorl(first_high, high); | 
 | 6765 |         } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6766 |       } | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6767 |     } | 
 | 6768 |   } | 
 | 6769 | } | 
 | 6770 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6771 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, | 
 | 6772 |                                                                    Location out, | 
 | 6773 |                                                                    uint32_t offset, | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6774 |                                                                    Location maybe_temp) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6775 |   Register out_reg = out.AsRegister<Register>(); | 
 | 6776 |   if (kEmitCompilerReadBarrier) { | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6777 |     DCHECK(maybe_temp.IsRegister()) << maybe_temp; | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6778 |     if (kUseBakerReadBarrier) { | 
 | 6779 |       // Load with fast path based Baker's read barrier. | 
 | 6780 |       // /* HeapReference<Object> */ out = *(out + offset) | 
 | 6781 |       codegen_->GenerateFieldLoadWithBakerReadBarrier( | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6782 |           instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6783 |     } else { | 
 | 6784 |       // Load with slow path based read barrier. | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6785 |       // Save the value of `out` into `maybe_temp` before overwriting it | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6786 |       // in the following move operation, as we will need it for the | 
 | 6787 |       // read barrier below. | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6788 |       __ movl(maybe_temp.AsRegister<Register>(), out_reg); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6789 |       // /* HeapReference<Object> */ out = *(out + offset) | 
 | 6790 |       __ movl(out_reg, Address(out_reg, offset)); | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6791 |       codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6792 |     } | 
 | 6793 |   } else { | 
 | 6794 |     // Plain load with no read barrier. | 
 | 6795 |     // /* HeapReference<Object> */ out = *(out + offset) | 
 | 6796 |     __ movl(out_reg, Address(out_reg, offset)); | 
 | 6797 |     __ MaybeUnpoisonHeapReference(out_reg); | 
 | 6798 |   } | 
 | 6799 | } | 
 | 6800 |  | 
 | 6801 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, | 
 | 6802 |                                                                     Location out, | 
 | 6803 |                                                                     Location obj, | 
 | 6804 |                                                                     uint32_t offset, | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6805 |                                                                     Location maybe_temp) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6806 |   Register out_reg = out.AsRegister<Register>(); | 
 | 6807 |   Register obj_reg = obj.AsRegister<Register>(); | 
 | 6808 |   if (kEmitCompilerReadBarrier) { | 
 | 6809 |     if (kUseBakerReadBarrier) { | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6810 |       DCHECK(maybe_temp.IsRegister()) << maybe_temp; | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6811 |       // Load with fast path based Baker's read barrier. | 
 | 6812 |       // /* HeapReference<Object> */ out = *(obj + offset) | 
 | 6813 |       codegen_->GenerateFieldLoadWithBakerReadBarrier( | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6814 |           instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6815 |     } else { | 
 | 6816 |       // Load with slow path based read barrier. | 
 | 6817 |       // /* HeapReference<Object> */ out = *(obj + offset) | 
 | 6818 |       __ movl(out_reg, Address(obj_reg, offset)); | 
 | 6819 |       codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); | 
 | 6820 |     } | 
 | 6821 |   } else { | 
 | 6822 |     // Plain load with no read barrier. | 
 | 6823 |     // /* HeapReference<Object> */ out = *(obj + offset) | 
 | 6824 |     __ movl(out_reg, Address(obj_reg, offset)); | 
 | 6825 |     __ MaybeUnpoisonHeapReference(out_reg); | 
 | 6826 |   } | 
 | 6827 | } | 
 | 6828 |  | 
 | 6829 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, | 
 | 6830 |                                                           Location root, | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6831 |                                                           const Address& address, | 
 | 6832 |                                                           Label* fixup_label) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6833 |   Register root_reg = root.AsRegister<Register>(); | 
 | 6834 |   if (kEmitCompilerReadBarrier) { | 
 | 6835 |     if (kUseBakerReadBarrier) { | 
 | 6836 |       // Fast path implementation of art::ReadBarrier::BarrierForRoot when | 
 | 6837 |       // Baker's read barrier are used: | 
 | 6838 |       // | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6839 |       //   root = *address; | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6840 |       //   if (Thread::Current()->GetIsGcMarking()) { | 
 | 6841 |       //     root = ReadBarrier::Mark(root) | 
 | 6842 |       //   } | 
 | 6843 |  | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6844 |       // /* GcRoot<mirror::Object> */ root = *address | 
 | 6845 |       __ movl(root_reg, address); | 
 | 6846 |       if (fixup_label != nullptr) { | 
 | 6847 |         __ Bind(fixup_label); | 
 | 6848 |       } | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6849 |       static_assert( | 
 | 6850 |           sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), | 
 | 6851 |           "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " | 
 | 6852 |           "have different sizes."); | 
 | 6853 |       static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), | 
 | 6854 |                     "art::mirror::CompressedReference<mirror::Object> and int32_t " | 
 | 6855 |                     "have different sizes."); | 
 | 6856 |  | 
 | 6857 |       // Slow path used to mark the GC root `root`. | 
 | 6858 |       SlowPathCode* slow_path = | 
 | 6859 |           new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); | 
 | 6860 |       codegen_->AddSlowPath(slow_path); | 
 | 6861 |  | 
 | 6862 |       __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), | 
 | 6863 |                     Immediate(0)); | 
 | 6864 |       __ j(kNotEqual, slow_path->GetEntryLabel()); | 
 | 6865 |       __ Bind(slow_path->GetExitLabel()); | 
 | 6866 |     } else { | 
 | 6867 |       // GC root loaded through a slow path for read barriers other | 
 | 6868 |       // than Baker's. | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6869 |       // /* GcRoot<mirror::Object>* */ root = address | 
 | 6870 |       __ leal(root_reg, address); | 
 | 6871 |       if (fixup_label != nullptr) { | 
 | 6872 |         __ Bind(fixup_label); | 
 | 6873 |       } | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6874 |       // /* mirror::Object* */ root = root->Read() | 
 | 6875 |       codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); | 
 | 6876 |     } | 
 | 6877 |   } else { | 
 | 6878 |     // Plain GC root load with no read barrier. | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6879 |     // /* GcRoot<mirror::Object> */ root = *address | 
 | 6880 |     __ movl(root_reg, address); | 
 | 6881 |     if (fixup_label != nullptr) { | 
 | 6882 |       __ Bind(fixup_label); | 
 | 6883 |     } | 
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6884 |     // Note that GC roots are not affected by heap poisoning, thus we | 
 | 6885 |     // do not have to unpoison `root_reg` here. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6886 |   } | 
 | 6887 | } | 
 | 6888 |  | 
 | 6889 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, | 
 | 6890 |                                                              Location ref, | 
 | 6891 |                                                              Register obj, | 
 | 6892 |                                                              uint32_t offset, | 
 | 6893 |                                                              Location temp, | 
 | 6894 |                                                              bool needs_null_check) { | 
 | 6895 |   DCHECK(kEmitCompilerReadBarrier); | 
 | 6896 |   DCHECK(kUseBakerReadBarrier); | 
 | 6897 |  | 
 | 6898 |   // /* HeapReference<Object> */ ref = *(obj + offset) | 
 | 6899 |   Address src(obj, offset); | 
 | 6900 |   GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); | 
 | 6901 | } | 
 | 6902 |  | 
 | 6903 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, | 
 | 6904 |                                                              Location ref, | 
 | 6905 |                                                              Register obj, | 
 | 6906 |                                                              uint32_t data_offset, | 
 | 6907 |                                                              Location index, | 
 | 6908 |                                                              Location temp, | 
 | 6909 |                                                              bool needs_null_check) { | 
 | 6910 |   DCHECK(kEmitCompilerReadBarrier); | 
 | 6911 |   DCHECK(kUseBakerReadBarrier); | 
 | 6912 |  | 
 | 6913 |   // /* HeapReference<Object> */ ref = | 
 | 6914 |   //     *(obj + data_offset + index * sizeof(HeapReference<Object>)) | 
 | 6915 |   Address src = index.IsConstant() ? | 
 | 6916 |       Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : | 
 | 6917 |       Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); | 
 | 6918 |   GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); | 
 | 6919 | } | 
 | 6920 |  | 
 | 6921 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, | 
 | 6922 |                                                                  Location ref, | 
 | 6923 |                                                                  Register obj, | 
 | 6924 |                                                                  const Address& src, | 
 | 6925 |                                                                  Location temp, | 
 | 6926 |                                                                  bool needs_null_check) { | 
 | 6927 |   DCHECK(kEmitCompilerReadBarrier); | 
 | 6928 |   DCHECK(kUseBakerReadBarrier); | 
 | 6929 |  | 
 | 6930 |   // In slow path based read barriers, the read barrier call is | 
 | 6931 |   // inserted after the original load. However, in fast path based | 
 | 6932 |   // Baker's read barriers, we need to perform the load of | 
 | 6933 |   // mirror::Object::monitor_ *before* the original reference load. | 
 | 6934 |   // This load-load ordering is required by the read barrier. | 
 | 6935 |   // The fast path/slow path (for Baker's algorithm) should look like: | 
 | 6936 |   // | 
 | 6937 |   //   uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); | 
 | 6938 |   //   lfence;  // Load fence or artificial data dependency to prevent load-load reordering | 
 | 6939 |   //   HeapReference<Object> ref = *src;  // Original reference load. | 
 | 6940 |   //   bool is_gray = (rb_state == ReadBarrier::gray_ptr_); | 
 | 6941 |   //   if (is_gray) { | 
 | 6942 |   //     ref = ReadBarrier::Mark(ref);  // Performed by runtime entrypoint slow path. | 
 | 6943 |   //   } | 
 | 6944 |   // | 
 | 6945 |   // Note: the original implementation in ReadBarrier::Barrier is | 
 | 6946 |   // slightly more complex as: | 
 | 6947 |   // - it implements the load-load fence using a data dependency on | 
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6948 |   //   the high-bits of rb_state, which are expected to be all zeroes | 
 | 6949 |   //   (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, | 
 | 6950 |   //   which is a no-op thanks to the x86 memory model); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6951 |   // - it performs additional checks that we do not do here for | 
 | 6952 |   //   performance reasons. | 
 | 6953 |  | 
 | 6954 |   Register ref_reg = ref.AsRegister<Register>(); | 
 | 6955 |   Register temp_reg = temp.AsRegister<Register>(); | 
 | 6956 |   uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); | 
 | 6957 |  | 
 | 6958 |   // /* int32_t */ monitor = obj->monitor_ | 
 | 6959 |   __ movl(temp_reg, Address(obj, monitor_offset)); | 
 | 6960 |   if (needs_null_check) { | 
 | 6961 |     MaybeRecordImplicitNullCheck(instruction); | 
 | 6962 |   } | 
 | 6963 |   // /* LockWord */ lock_word = LockWord(monitor) | 
 | 6964 |   static_assert(sizeof(LockWord) == sizeof(int32_t), | 
 | 6965 |                 "art::LockWord and int32_t have different sizes."); | 
 | 6966 |   // /* uint32_t */ rb_state = lock_word.ReadBarrierState() | 
 | 6967 |   __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); | 
 | 6968 |   __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); | 
 | 6969 |   static_assert( | 
 | 6970 |       LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, | 
 | 6971 |       "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); | 
 | 6972 |  | 
 | 6973 |   // Load fence to prevent load-load reordering. | 
 | 6974 |   // Note that this is a no-op, thanks to the x86 memory model. | 
 | 6975 |   GenerateMemoryBarrier(MemBarrierKind::kLoadAny); | 
 | 6976 |  | 
 | 6977 |   // The actual reference load. | 
 | 6978 |   // /* HeapReference<Object> */ ref = *src | 
 | 6979 |   __ movl(ref_reg, src); | 
 | 6980 |  | 
 | 6981 |   // Object* ref = ref_addr->AsMirrorPtr() | 
 | 6982 |   __ MaybeUnpoisonHeapReference(ref_reg); | 
 | 6983 |  | 
 | 6984 |   // Slow path used to mark the object `ref` when it is gray. | 
 | 6985 |   SlowPathCode* slow_path = | 
 | 6986 |       new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); | 
 | 6987 |   AddSlowPath(slow_path); | 
 | 6988 |  | 
 | 6989 |   // if (rb_state == ReadBarrier::gray_ptr_) | 
 | 6990 |   //   ref = ReadBarrier::Mark(ref); | 
 | 6991 |   __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); | 
 | 6992 |   __ j(kEqual, slow_path->GetEntryLabel()); | 
 | 6993 |   __ Bind(slow_path->GetExitLabel()); | 
 | 6994 | } | 
 | 6995 |  | 
 | 6996 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, | 
 | 6997 |                                                Location out, | 
 | 6998 |                                                Location ref, | 
 | 6999 |                                                Location obj, | 
 | 7000 |                                                uint32_t offset, | 
 | 7001 |                                                Location index) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7002 |   DCHECK(kEmitCompilerReadBarrier); | 
 | 7003 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7004 |   // Insert a slow path based read barrier *after* the reference load. | 
 | 7005 |   // | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7006 |   // If heap poisoning is enabled, the unpoisoning of the loaded | 
 | 7007 |   // reference will be carried out by the runtime within the slow | 
 | 7008 |   // path. | 
 | 7009 |   // | 
 | 7010 |   // Note that `ref` currently does not get unpoisoned (when heap | 
 | 7011 |   // poisoning is enabled), which is alright as the `ref` argument is | 
 | 7012 |   // not used by the artReadBarrierSlow entry point. | 
 | 7013 |   // | 
 | 7014 |   // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. | 
 | 7015 |   SlowPathCode* slow_path = new (GetGraph()->GetArena()) | 
 | 7016 |       ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); | 
 | 7017 |   AddSlowPath(slow_path); | 
 | 7018 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7019 |   __ jmp(slow_path->GetEntryLabel()); | 
 | 7020 |   __ Bind(slow_path->GetExitLabel()); | 
 | 7021 | } | 
 | 7022 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7023 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, | 
 | 7024 |                                                     Location out, | 
 | 7025 |                                                     Location ref, | 
 | 7026 |                                                     Location obj, | 
 | 7027 |                                                     uint32_t offset, | 
 | 7028 |                                                     Location index) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7029 |   if (kEmitCompilerReadBarrier) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7030 |     // Baker's read barriers shall be handled by the fast path | 
 | 7031 |     // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). | 
 | 7032 |     DCHECK(!kUseBakerReadBarrier); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7033 |     // If heap poisoning is enabled, unpoisoning will be taken care of | 
 | 7034 |     // by the runtime within the slow path. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7035 |     GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7036 |   } else if (kPoisonHeapReferences) { | 
 | 7037 |     __ UnpoisonHeapReference(out.AsRegister<Register>()); | 
 | 7038 |   } | 
 | 7039 | } | 
 | 7040 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7041 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, | 
 | 7042 |                                                       Location out, | 
 | 7043 |                                                       Location root) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7044 |   DCHECK(kEmitCompilerReadBarrier); | 
 | 7045 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7046 |   // Insert a slow path based read barrier *after* the GC root load. | 
 | 7047 |   // | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7048 |   // Note that GC roots are not affected by heap poisoning, so we do | 
 | 7049 |   // not need to do anything special for this here. | 
 | 7050 |   SlowPathCode* slow_path = | 
 | 7051 |       new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); | 
 | 7052 |   AddSlowPath(slow_path); | 
 | 7053 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7054 |   __ jmp(slow_path->GetEntryLabel()); | 
 | 7055 |   __ Bind(slow_path->GetExitLabel()); | 
 | 7056 | } | 
 | 7057 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7058 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { | 
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7059 |   // Nothing to do, this should be removed during prepare for register allocator. | 
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7060 |   LOG(FATAL) << "Unreachable"; | 
 | 7061 | } | 
 | 7062 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7063 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { | 
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7064 |   // Nothing to do, this should be removed during prepare for register allocator. | 
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7065 |   LOG(FATAL) << "Unreachable"; | 
 | 7066 | } | 
 | 7067 |  | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7068 | // Simple implementation of packed switch - generate cascaded compare/jumps. | 
 | 7069 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
 | 7070 |   LocationSummary* locations = | 
 | 7071 |       new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); | 
 | 7072 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 7073 | } | 
 | 7074 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7075 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, | 
 | 7076 |                                                               int32_t lower_bound, | 
 | 7077 |                                                               uint32_t num_entries, | 
 | 7078 |                                                               HBasicBlock* switch_block, | 
 | 7079 |                                                               HBasicBlock* default_block) { | 
 | 7080 |   // Figure out the correct compare values and jump conditions. | 
 | 7081 |   // Handle the first compare/branch as a special case because it might | 
 | 7082 |   // jump to the default case. | 
 | 7083 |   DCHECK_GT(num_entries, 2u); | 
 | 7084 |   Condition first_condition; | 
 | 7085 |   uint32_t index; | 
 | 7086 |   const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); | 
 | 7087 |   if (lower_bound != 0) { | 
 | 7088 |     first_condition = kLess; | 
 | 7089 |     __ cmpl(value_reg, Immediate(lower_bound)); | 
 | 7090 |     __ j(first_condition, codegen_->GetLabelOf(default_block)); | 
 | 7091 |     __ j(kEqual, codegen_->GetLabelOf(successors[0])); | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7092 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7093 |     index = 1; | 
 | 7094 |   } else { | 
 | 7095 |     // Handle all the compare/jumps below. | 
 | 7096 |     first_condition = kBelow; | 
 | 7097 |     index = 0; | 
 | 7098 |   } | 
 | 7099 |  | 
 | 7100 |   // Handle the rest of the compare/jumps. | 
 | 7101 |   for (; index + 1 < num_entries; index += 2) { | 
 | 7102 |     int32_t compare_to_value = lower_bound + index + 1; | 
 | 7103 |     __ cmpl(value_reg, Immediate(compare_to_value)); | 
 | 7104 |     // Jump to successors[index] if value < case_value[index]. | 
 | 7105 |     __ j(first_condition, codegen_->GetLabelOf(successors[index])); | 
 | 7106 |     // Jump to successors[index + 1] if value == case_value[index + 1]. | 
 | 7107 |     __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); | 
 | 7108 |   } | 
 | 7109 |  | 
 | 7110 |   if (index != num_entries) { | 
 | 7111 |     // There are an odd number of entries. Handle the last one. | 
 | 7112 |     DCHECK_EQ(index + 1, num_entries); | 
 | 7113 |     __ cmpl(value_reg, Immediate(lower_bound + index)); | 
 | 7114 |     __ j(kEqual, codegen_->GetLabelOf(successors[index])); | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7115 |   } | 
 | 7116 |  | 
 | 7117 |   // And the default for any other value. | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7118 |   if (!codegen_->GoesToNextBlock(switch_block, default_block)) { | 
 | 7119 |     __ jmp(codegen_->GetLabelOf(default_block)); | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7120 |   } | 
 | 7121 | } | 
 | 7122 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7123 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
 | 7124 |   int32_t lower_bound = switch_instr->GetStartValue(); | 
 | 7125 |   uint32_t num_entries = switch_instr->GetNumEntries(); | 
 | 7126 |   LocationSummary* locations = switch_instr->GetLocations(); | 
 | 7127 |   Register value_reg = locations->InAt(0).AsRegister<Register>(); | 
 | 7128 |  | 
 | 7129 |   GenPackedSwitchWithCompares(value_reg, | 
 | 7130 |                               lower_bound, | 
 | 7131 |                               num_entries, | 
 | 7132 |                               switch_instr->GetBlock(), | 
 | 7133 |                               switch_instr->GetDefaultBlock()); | 
 | 7134 | } | 
 | 7135 |  | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7136 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { | 
 | 7137 |   LocationSummary* locations = | 
 | 7138 |       new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); | 
 | 7139 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 7140 |  | 
 | 7141 |   // Constant area pointer. | 
 | 7142 |   locations->SetInAt(1, Location::RequiresRegister()); | 
 | 7143 |  | 
 | 7144 |   // And the temporary we need. | 
 | 7145 |   locations->AddTemp(Location::RequiresRegister()); | 
 | 7146 | } | 
 | 7147 |  | 
 | 7148 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { | 
 | 7149 |   int32_t lower_bound = switch_instr->GetStartValue(); | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7150 |   uint32_t num_entries = switch_instr->GetNumEntries(); | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7151 |   LocationSummary* locations = switch_instr->GetLocations(); | 
 | 7152 |   Register value_reg = locations->InAt(0).AsRegister<Register>(); | 
 | 7153 |   HBasicBlock* default_block = switch_instr->GetDefaultBlock(); | 
 | 7154 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7155 |   if (num_entries <= kPackedSwitchJumpTableThreshold) { | 
 | 7156 |     GenPackedSwitchWithCompares(value_reg, | 
 | 7157 |                                 lower_bound, | 
 | 7158 |                                 num_entries, | 
 | 7159 |                                 switch_instr->GetBlock(), | 
 | 7160 |                                 default_block); | 
 | 7161 |     return; | 
 | 7162 |   } | 
 | 7163 |  | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7164 |   // Optimizing has a jump area. | 
 | 7165 |   Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); | 
 | 7166 |   Register constant_area = locations->InAt(1).AsRegister<Register>(); | 
 | 7167 |  | 
 | 7168 |   // Remove the bias, if needed. | 
 | 7169 |   if (lower_bound != 0) { | 
 | 7170 |     __ leal(temp_reg, Address(value_reg, -lower_bound)); | 
 | 7171 |     value_reg = temp_reg; | 
 | 7172 |   } | 
 | 7173 |  | 
 | 7174 |   // Is the value in range? | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7175 |   DCHECK_GE(num_entries, 1u); | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7176 |   __ cmpl(value_reg, Immediate(num_entries - 1)); | 
 | 7177 |   __ j(kAbove, codegen_->GetLabelOf(default_block)); | 
 | 7178 |  | 
 | 7179 |   // We are in the range of the table. | 
 | 7180 |   // Load (target-constant_area) from the jump table, indexing by the value. | 
 | 7181 |   __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); | 
 | 7182 |  | 
 | 7183 |   // Compute the actual target address by adding in constant_area. | 
 | 7184 |   __ addl(temp_reg, constant_area); | 
 | 7185 |  | 
 | 7186 |   // And jump. | 
 | 7187 |   __ jmp(temp_reg); | 
 | 7188 | } | 
 | 7189 |  | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7190 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( | 
 | 7191 |     HX86ComputeBaseMethodAddress* insn) { | 
 | 7192 |   LocationSummary* locations = | 
 | 7193 |       new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); | 
 | 7194 |   locations->SetOut(Location::RequiresRegister()); | 
 | 7195 | } | 
 | 7196 |  | 
 | 7197 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( | 
 | 7198 |     HX86ComputeBaseMethodAddress* insn) { | 
 | 7199 |   LocationSummary* locations = insn->GetLocations(); | 
 | 7200 |   Register reg = locations->Out().AsRegister<Register>(); | 
 | 7201 |  | 
 | 7202 |   // Generate call to next instruction. | 
 | 7203 |   Label next_instruction; | 
 | 7204 |   __ call(&next_instruction); | 
 | 7205 |   __ Bind(&next_instruction); | 
 | 7206 |  | 
 | 7207 |   // Remember this offset for later use with constant area. | 
 | 7208 |   codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); | 
 | 7209 |  | 
 | 7210 |   // Grab the return address off the stack. | 
 | 7211 |   __ popl(reg); | 
 | 7212 | } | 
 | 7213 |  | 
 | 7214 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( | 
 | 7215 |     HX86LoadFromConstantTable* insn) { | 
 | 7216 |   LocationSummary* locations = | 
 | 7217 |       new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); | 
 | 7218 |  | 
 | 7219 |   locations->SetInAt(0, Location::RequiresRegister()); | 
 | 7220 |   locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); | 
 | 7221 |  | 
 | 7222 |   // If we don't need to be materialized, we only need the inputs to be set. | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7223 |   if (insn->IsEmittedAtUseSite()) { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7224 |     return; | 
 | 7225 |   } | 
 | 7226 |  | 
 | 7227 |   switch (insn->GetType()) { | 
 | 7228 |     case Primitive::kPrimFloat: | 
 | 7229 |     case Primitive::kPrimDouble: | 
 | 7230 |       locations->SetOut(Location::RequiresFpuRegister()); | 
 | 7231 |       break; | 
 | 7232 |  | 
 | 7233 |     case Primitive::kPrimInt: | 
 | 7234 |       locations->SetOut(Location::RequiresRegister()); | 
 | 7235 |       break; | 
 | 7236 |  | 
 | 7237 |     default: | 
 | 7238 |       LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); | 
 | 7239 |   } | 
 | 7240 | } | 
 | 7241 |  | 
 | 7242 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7243 |   if (insn->IsEmittedAtUseSite()) { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7244 |     return; | 
 | 7245 |   } | 
 | 7246 |  | 
 | 7247 |   LocationSummary* locations = insn->GetLocations(); | 
 | 7248 |   Location out = locations->Out(); | 
 | 7249 |   Register const_area = locations->InAt(0).AsRegister<Register>(); | 
 | 7250 |   HConstant *value = insn->GetConstant(); | 
 | 7251 |  | 
 | 7252 |   switch (insn->GetType()) { | 
 | 7253 |     case Primitive::kPrimFloat: | 
 | 7254 |       __ movss(out.AsFpuRegister<XmmRegister>(), | 
 | 7255 |                codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); | 
 | 7256 |       break; | 
 | 7257 |  | 
 | 7258 |     case Primitive::kPrimDouble: | 
 | 7259 |       __ movsd(out.AsFpuRegister<XmmRegister>(), | 
 | 7260 |                codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); | 
 | 7261 |       break; | 
 | 7262 |  | 
 | 7263 |     case Primitive::kPrimInt: | 
 | 7264 |       __ movl(out.AsRegister<Register>(), | 
 | 7265 |               codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); | 
 | 7266 |       break; | 
 | 7267 |  | 
 | 7268 |     default: | 
 | 7269 |       LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); | 
 | 7270 |   } | 
 | 7271 | } | 
 | 7272 |  | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7273 | /** | 
 | 7274 |  * Class to handle late fixup of offsets into constant area. | 
 | 7275 |  */ | 
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7276 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7277 |  public: | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7278 |   RIPFixup(CodeGeneratorX86& codegen, size_t offset) | 
 | 7279 |       : codegen_(&codegen), offset_into_constant_area_(offset) {} | 
 | 7280 |  | 
 | 7281 |  protected: | 
 | 7282 |   void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } | 
 | 7283 |  | 
 | 7284 |   CodeGeneratorX86* codegen_; | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7285 |  | 
 | 7286 |  private: | 
 | 7287 |   void Process(const MemoryRegion& region, int pos) OVERRIDE { | 
 | 7288 |     // Patch the correct offset for the instruction.  The place to patch is the | 
 | 7289 |     // last 4 bytes of the instruction. | 
 | 7290 |     // The value to patch is the distance from the offset in the constant area | 
 | 7291 |     // from the address computed by the HX86ComputeBaseMethodAddress instruction. | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7292 |     int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; | 
 | 7293 |     int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7294 |  | 
 | 7295 |     // Patch in the right value. | 
 | 7296 |     region.StoreUnaligned<int32_t>(pos - 4, relative_position); | 
 | 7297 |   } | 
 | 7298 |  | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7299 |   // Location in constant area that the fixup refers to. | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7300 |   int32_t offset_into_constant_area_; | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7301 | }; | 
 | 7302 |  | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7303 | /** | 
 | 7304 |  * Class to handle late fixup of offsets to a jump table that will be created in the | 
 | 7305 |  * constant area. | 
 | 7306 |  */ | 
 | 7307 | class JumpTableRIPFixup : public RIPFixup { | 
 | 7308 |  public: | 
 | 7309 |   JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) | 
 | 7310 |       : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} | 
 | 7311 |  | 
 | 7312 |   void CreateJumpTable() { | 
 | 7313 |     X86Assembler* assembler = codegen_->GetAssembler(); | 
 | 7314 |  | 
 | 7315 |     // Ensure that the reference to the jump table has the correct offset. | 
 | 7316 |     const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); | 
 | 7317 |     SetOffset(offset_in_constant_table); | 
 | 7318 |  | 
 | 7319 |     // The label values in the jump table are computed relative to the | 
 | 7320 |     // instruction addressing the constant area. | 
 | 7321 |     const int32_t relative_offset = codegen_->GetMethodAddressOffset(); | 
 | 7322 |  | 
 | 7323 |     // Populate the jump table with the correct values for the jump table. | 
 | 7324 |     int32_t num_entries = switch_instr_->GetNumEntries(); | 
 | 7325 |     HBasicBlock* block = switch_instr_->GetBlock(); | 
 | 7326 |     const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); | 
 | 7327 |     // The value that we want is the target offset - the position of the table. | 
 | 7328 |     for (int32_t i = 0; i < num_entries; i++) { | 
 | 7329 |       HBasicBlock* b = successors[i]; | 
 | 7330 |       Label* l = codegen_->GetLabelOf(b); | 
 | 7331 |       DCHECK(l->IsBound()); | 
 | 7332 |       int32_t offset_to_block = l->Position() - relative_offset; | 
 | 7333 |       assembler->AppendInt32(offset_to_block); | 
 | 7334 |     } | 
 | 7335 |   } | 
 | 7336 |  | 
 | 7337 |  private: | 
 | 7338 |   const HX86PackedSwitch* switch_instr_; | 
 | 7339 | }; | 
 | 7340 |  | 
 | 7341 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { | 
 | 7342 |   // Generate the constant area if needed. | 
 | 7343 |   X86Assembler* assembler = GetAssembler(); | 
 | 7344 |   if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { | 
 | 7345 |     // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 | 
 | 7346 |     // byte values. | 
 | 7347 |     assembler->Align(4, 0); | 
 | 7348 |     constant_area_start_ = assembler->CodeSize(); | 
 | 7349 |  | 
 | 7350 |     // Populate any jump tables. | 
 | 7351 |     for (auto jump_table : fixups_to_jump_tables_) { | 
 | 7352 |       jump_table->CreateJumpTable(); | 
 | 7353 |     } | 
 | 7354 |  | 
 | 7355 |     // And now add the constant area to the generated code. | 
 | 7356 |     assembler->AddConstantArea(); | 
 | 7357 |   } | 
 | 7358 |  | 
 | 7359 |   // And finish up. | 
 | 7360 |   CodeGenerator::Finalize(allocator); | 
 | 7361 | } | 
 | 7362 |  | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7363 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { | 
 | 7364 |   AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); | 
 | 7365 |   return Address(reg, kDummy32BitOffset, fixup); | 
 | 7366 | } | 
 | 7367 |  | 
 | 7368 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { | 
 | 7369 |   AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); | 
 | 7370 |   return Address(reg, kDummy32BitOffset, fixup); | 
 | 7371 | } | 
 | 7372 |  | 
 | 7373 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { | 
 | 7374 |   AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); | 
 | 7375 |   return Address(reg, kDummy32BitOffset, fixup); | 
 | 7376 | } | 
 | 7377 |  | 
 | 7378 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { | 
 | 7379 |   AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); | 
 | 7380 |   return Address(reg, kDummy32BitOffset, fixup); | 
 | 7381 | } | 
 | 7382 |  | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7383 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { | 
 | 7384 |   if (value == 0) { | 
 | 7385 |     __ xorl(dest, dest); | 
 | 7386 |   } else { | 
 | 7387 |     __ movl(dest, Immediate(value)); | 
 | 7388 |   } | 
 | 7389 | } | 
 | 7390 |  | 
 | 7391 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { | 
 | 7392 |   if (value == 0) { | 
 | 7393 |     __ testl(dest, dest); | 
 | 7394 |   } else { | 
 | 7395 |     __ cmpl(dest, Immediate(value)); | 
 | 7396 |   } | 
 | 7397 | } | 
 | 7398 |  | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7399 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, | 
 | 7400 |                                            Register reg, | 
 | 7401 |                                            Register value) { | 
 | 7402 |   // Create a fixup to be used to create and address the jump table. | 
 | 7403 |   JumpTableRIPFixup* table_fixup = | 
 | 7404 |       new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); | 
 | 7405 |  | 
 | 7406 |   // We have to populate the jump tables. | 
 | 7407 |   fixups_to_jump_tables_.push_back(table_fixup); | 
 | 7408 |  | 
 | 7409 |   // We want a scaled address, as we are extracting the correct offset from the table. | 
 | 7410 |   return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); | 
 | 7411 | } | 
 | 7412 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7413 | // TODO: target as memory. | 
 | 7414 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { | 
 | 7415 |   if (!target.IsValid()) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7416 |     DCHECK_EQ(type, Primitive::kPrimVoid); | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7417 |     return; | 
 | 7418 |   } | 
 | 7419 |  | 
 | 7420 |   DCHECK_NE(type, Primitive::kPrimVoid); | 
 | 7421 |  | 
 | 7422 |   Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); | 
 | 7423 |   if (target.Equals(return_loc)) { | 
 | 7424 |     return; | 
 | 7425 |   } | 
 | 7426 |  | 
 | 7427 |   // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged | 
 | 7428 |   //       with the else branch. | 
 | 7429 |   if (type == Primitive::kPrimLong) { | 
 | 7430 |     HParallelMove parallel_move(GetGraph()->GetArena()); | 
 | 7431 |     parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); | 
 | 7432 |     parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); | 
 | 7433 |     GetMoveResolver()->EmitNativeCode(¶llel_move); | 
 | 7434 |   } else { | 
 | 7435 |     // Let the parallel move resolver take care of all of this. | 
 | 7436 |     HParallelMove parallel_move(GetGraph()->GetArena()); | 
 | 7437 |     parallel_move.AddMove(return_loc, target, type, nullptr); | 
 | 7438 |     GetMoveResolver()->EmitNativeCode(¶llel_move); | 
 | 7439 |   } | 
 | 7440 | } | 
 | 7441 |  | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7442 | #undef __ | 
 | 7443 |  | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7444 | }  // namespace x86 | 
 | 7445 | }  // namespace art |