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)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 802 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 803 | // Use a fake return address register to mimic Quick. |
| 804 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 805 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 806 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 807 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 808 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 809 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 810 | |
| 811 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 812 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 813 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 814 | UpdateBlockedPairRegisters(); |
| 815 | } |
| 816 | |
| 817 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 818 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 819 | X86ManagedRegister current = |
| 820 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 821 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 822 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 823 | blocked_register_pairs_[i] = true; |
| 824 | } |
| 825 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 826 | } |
| 827 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 828 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 829 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 830 | assembler_(codegen->GetAssembler()), |
| 831 | codegen_(codegen) {} |
| 832 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 833 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 834 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 835 | } |
| 836 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 837 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 838 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 839 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 840 | bool skip_overflow_check = |
| 841 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 842 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 843 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 844 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 845 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 846 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 847 | } |
| 848 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 849 | if (HasEmptyFrame()) { |
| 850 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 851 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 852 | |
| 853 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 854 | Register reg = kCoreCalleeSaves[i]; |
| 855 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 856 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 857 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 858 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 862 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 863 | __ subl(ESP, Immediate(adjust)); |
| 864 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 865 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 869 | __ cfi().RememberState(); |
| 870 | if (!HasEmptyFrame()) { |
| 871 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 872 | __ addl(ESP, Immediate(adjust)); |
| 873 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 874 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 875 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 876 | Register reg = kCoreCalleeSaves[i]; |
| 877 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 878 | __ popl(reg); |
| 879 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 880 | __ cfi().Restore(DWARFReg(reg)); |
| 881 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 882 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 883 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 884 | __ ret(); |
| 885 | __ cfi().RestoreState(); |
| 886 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 887 | } |
| 888 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 889 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 890 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 893 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 894 | switch (load->GetType()) { |
| 895 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 896 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 897 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 898 | |
| 899 | case Primitive::kPrimInt: |
| 900 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 901 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 902 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 903 | |
| 904 | case Primitive::kPrimBoolean: |
| 905 | case Primitive::kPrimByte: |
| 906 | case Primitive::kPrimChar: |
| 907 | case Primitive::kPrimShort: |
| 908 | case Primitive::kPrimVoid: |
| 909 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 910 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 914 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 915 | } |
| 916 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 917 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 918 | switch (type) { |
| 919 | case Primitive::kPrimBoolean: |
| 920 | case Primitive::kPrimByte: |
| 921 | case Primitive::kPrimChar: |
| 922 | case Primitive::kPrimShort: |
| 923 | case Primitive::kPrimInt: |
| 924 | case Primitive::kPrimNot: |
| 925 | return Location::RegisterLocation(EAX); |
| 926 | |
| 927 | case Primitive::kPrimLong: |
| 928 | return Location::RegisterPairLocation(EAX, EDX); |
| 929 | |
| 930 | case Primitive::kPrimVoid: |
| 931 | return Location::NoLocation(); |
| 932 | |
| 933 | case Primitive::kPrimDouble: |
| 934 | case Primitive::kPrimFloat: |
| 935 | return Location::FpuRegisterLocation(XMM0); |
| 936 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 937 | |
| 938 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 942 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 943 | } |
| 944 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 945 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 946 | switch (type) { |
| 947 | case Primitive::kPrimBoolean: |
| 948 | case Primitive::kPrimByte: |
| 949 | case Primitive::kPrimChar: |
| 950 | case Primitive::kPrimShort: |
| 951 | case Primitive::kPrimInt: |
| 952 | case Primitive::kPrimNot: { |
| 953 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 954 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 955 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 956 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 957 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 958 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 959 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 960 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 961 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 962 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 963 | uint32_t index = gp_index_; |
| 964 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 965 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 966 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 967 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 968 | calling_convention.GetRegisterPairAt(index)); |
| 969 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 970 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 971 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 976 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 977 | stack_index_++; |
| 978 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 979 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 980 | } else { |
| 981 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 986 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 987 | stack_index_ += 2; |
| 988 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 989 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 990 | } else { |
| 991 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 995 | case Primitive::kPrimVoid: |
| 996 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 997 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 998 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 999 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1000 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1001 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1002 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1003 | if (source.Equals(destination)) { |
| 1004 | return; |
| 1005 | } |
| 1006 | if (destination.IsRegister()) { |
| 1007 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1008 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1009 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1010 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1011 | } else { |
| 1012 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1013 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1014 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1015 | } else if (destination.IsFpuRegister()) { |
| 1016 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1017 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1018 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1019 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1020 | } else { |
| 1021 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1022 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1023 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1024 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1025 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1026 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1027 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1028 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1029 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1030 | } else if (source.IsConstant()) { |
| 1031 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1032 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1033 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1034 | } else { |
| 1035 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1036 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1037 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1043 | if (source.Equals(destination)) { |
| 1044 | return; |
| 1045 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1046 | if (destination.IsRegisterPair()) { |
| 1047 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1048 | EmitParallelMoves( |
| 1049 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1050 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1051 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1052 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1053 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1054 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1055 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1056 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1057 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1058 | __ psrlq(src_reg, Immediate(32)); |
| 1059 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1060 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1061 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1062 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1063 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1064 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1065 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1066 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1067 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1068 | if (source.IsFpuRegister()) { |
| 1069 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1070 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1071 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1072 | } else if (source.IsRegisterPair()) { |
| 1073 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1074 | // Create stack space for 2 elements. |
| 1075 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1076 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1077 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1078 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1079 | // And remove the temporary stack space we allocated. |
| 1080 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1081 | } else { |
| 1082 | LOG(FATAL) << "Unimplemented"; |
| 1083 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1084 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1085 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1086 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1087 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1088 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1089 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1090 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1091 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1092 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1093 | } else if (source.IsConstant()) { |
| 1094 | HConstant* constant = source.GetConstant(); |
| 1095 | int64_t value; |
| 1096 | if (constant->IsLongConstant()) { |
| 1097 | value = constant->AsLongConstant()->GetValue(); |
| 1098 | } else { |
| 1099 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1100 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1101 | } |
| 1102 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1103 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1104 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1105 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1106 | EmitParallelMoves( |
| 1107 | Location::StackSlot(source.GetStackIndex()), |
| 1108 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1109 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1110 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1111 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1112 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1117 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1118 | DCHECK(location.IsRegister()); |
| 1119 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1120 | } |
| 1121 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1122 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1123 | HParallelMove move(GetGraph()->GetArena()); |
| 1124 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1125 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1126 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1127 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1128 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1129 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1130 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1134 | if (location.IsRegister()) { |
| 1135 | locations->AddTemp(location); |
| 1136 | } else if (location.IsRegisterPair()) { |
| 1137 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1138 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1139 | } else { |
| 1140 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1141 | } |
| 1142 | } |
| 1143 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1144 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1145 | DCHECK(!successor->IsExitBlock()); |
| 1146 | |
| 1147 | HBasicBlock* block = got->GetBlock(); |
| 1148 | HInstruction* previous = got->GetPrevious(); |
| 1149 | |
| 1150 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1151 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1152 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1153 | return; |
| 1154 | } |
| 1155 | |
| 1156 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1157 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1158 | } |
| 1159 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1160 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1161 | } |
| 1162 | } |
| 1163 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1164 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1165 | got->SetLocations(nullptr); |
| 1166 | } |
| 1167 | |
| 1168 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1169 | HandleGoto(got, got->GetSuccessor()); |
| 1170 | } |
| 1171 | |
| 1172 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1173 | try_boundary->SetLocations(nullptr); |
| 1174 | } |
| 1175 | |
| 1176 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1177 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1178 | if (!successor->IsExitBlock()) { |
| 1179 | HandleGoto(try_boundary, successor); |
| 1180 | } |
| 1181 | } |
| 1182 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1183 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1184 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1187 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1190 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1191 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1192 | LabelType* true_label, |
| 1193 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1194 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1195 | __ j(kUnordered, true_label); |
| 1196 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1197 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1198 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1199 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1200 | } |
| 1201 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1202 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1203 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1204 | LabelType* true_label, |
| 1205 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1206 | LocationSummary* locations = cond->GetLocations(); |
| 1207 | Location left = locations->InAt(0); |
| 1208 | Location right = locations->InAt(1); |
| 1209 | IfCondition if_cond = cond->GetCondition(); |
| 1210 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1211 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1212 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1213 | IfCondition true_high_cond = if_cond; |
| 1214 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1215 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1216 | |
| 1217 | // Set the conditions for the test, remembering that == needs to be |
| 1218 | // decided using the low words. |
| 1219 | switch (if_cond) { |
| 1220 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1221 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1222 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1223 | break; |
| 1224 | case kCondLT: |
| 1225 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1226 | break; |
| 1227 | case kCondLE: |
| 1228 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1229 | break; |
| 1230 | case kCondGT: |
| 1231 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1232 | break; |
| 1233 | case kCondGE: |
| 1234 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1235 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1236 | case kCondB: |
| 1237 | false_high_cond = kCondA; |
| 1238 | break; |
| 1239 | case kCondBE: |
| 1240 | true_high_cond = kCondB; |
| 1241 | break; |
| 1242 | case kCondA: |
| 1243 | false_high_cond = kCondB; |
| 1244 | break; |
| 1245 | case kCondAE: |
| 1246 | true_high_cond = kCondA; |
| 1247 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | if (right.IsConstant()) { |
| 1251 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1252 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1253 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1254 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1255 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1256 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1257 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1258 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1259 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1260 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1261 | __ j(X86Condition(true_high_cond), true_label); |
| 1262 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1263 | } |
| 1264 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1265 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1266 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1267 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1268 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1269 | |
| 1270 | __ cmpl(left_high, right_high); |
| 1271 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1272 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1273 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1274 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1275 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1276 | __ j(X86Condition(true_high_cond), true_label); |
| 1277 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1278 | } |
| 1279 | // Must be equal high, so compare the lows. |
| 1280 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1281 | } else { |
| 1282 | DCHECK(right.IsDoubleStackSlot()); |
| 1283 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1284 | if (if_cond == kCondNE) { |
| 1285 | __ j(X86Condition(true_high_cond), true_label); |
| 1286 | } else if (if_cond == kCondEQ) { |
| 1287 | __ j(X86Condition(false_high_cond), false_label); |
| 1288 | } else { |
| 1289 | __ j(X86Condition(true_high_cond), true_label); |
| 1290 | __ j(X86Condition(false_high_cond), false_label); |
| 1291 | } |
| 1292 | // Must be equal high, so compare the lows. |
| 1293 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1294 | } |
| 1295 | // The last comparison might be unsigned. |
| 1296 | __ j(final_condition, true_label); |
| 1297 | } |
| 1298 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1299 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1300 | Location rhs, |
| 1301 | HInstruction* insn, |
| 1302 | bool is_double) { |
| 1303 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1304 | if (is_double) { |
| 1305 | if (rhs.IsFpuRegister()) { |
| 1306 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1307 | } else if (const_area != nullptr) { |
| 1308 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1309 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1310 | codegen_->LiteralDoubleAddress( |
| 1311 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1312 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1313 | } else { |
| 1314 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1315 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1316 | } |
| 1317 | } else { |
| 1318 | if (rhs.IsFpuRegister()) { |
| 1319 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1320 | } else if (const_area != nullptr) { |
| 1321 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1322 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1323 | codegen_->LiteralFloatAddress( |
| 1324 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1325 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1326 | } else { |
| 1327 | DCHECK(rhs.IsStackSlot()); |
| 1328 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1333 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1334 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1335 | LabelType* true_target_in, |
| 1336 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1337 | // Generated branching requires both targets to be explicit. If either of the |
| 1338 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1339 | LabelType fallthrough_target; |
| 1340 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1341 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1342 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1343 | LocationSummary* locations = condition->GetLocations(); |
| 1344 | Location left = locations->InAt(0); |
| 1345 | Location right = locations->InAt(1); |
| 1346 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1347 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1348 | switch (type) { |
| 1349 | case Primitive::kPrimLong: |
| 1350 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1351 | break; |
| 1352 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1353 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1354 | GenerateFPJumps(condition, true_target, false_target); |
| 1355 | break; |
| 1356 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1357 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1358 | GenerateFPJumps(condition, true_target, false_target); |
| 1359 | break; |
| 1360 | default: |
| 1361 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1362 | } |
| 1363 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1364 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1365 | __ jmp(false_target); |
| 1366 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1367 | |
| 1368 | if (fallthrough_target.IsLinked()) { |
| 1369 | __ Bind(&fallthrough_target); |
| 1370 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1371 | } |
| 1372 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1373 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1374 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1375 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1376 | // conditions if they are materialized due to the complex branching. |
| 1377 | return cond->IsCondition() && |
| 1378 | cond->GetNext() == branch && |
| 1379 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1380 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1381 | } |
| 1382 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1383 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1384 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1385 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1386 | LabelType* true_target, |
| 1387 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1388 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1389 | |
| 1390 | if (true_target == nullptr && false_target == nullptr) { |
| 1391 | // Nothing to do. The code always falls through. |
| 1392 | return; |
| 1393 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1394 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1395 | if (cond->AsIntConstant()->IsOne()) { |
| 1396 | if (true_target != nullptr) { |
| 1397 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1398 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1399 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1400 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1401 | if (false_target != nullptr) { |
| 1402 | __ jmp(false_target); |
| 1403 | } |
| 1404 | } |
| 1405 | return; |
| 1406 | } |
| 1407 | |
| 1408 | // The following code generates these patterns: |
| 1409 | // (1) true_target == nullptr && false_target != nullptr |
| 1410 | // - opposite condition true => branch to false_target |
| 1411 | // (2) true_target != nullptr && false_target == nullptr |
| 1412 | // - condition true => branch to true_target |
| 1413 | // (3) true_target != nullptr && false_target != nullptr |
| 1414 | // - condition true => branch to true_target |
| 1415 | // - branch to false_target |
| 1416 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1417 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1418 | if (true_target == nullptr) { |
| 1419 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1420 | } else { |
| 1421 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1422 | } |
| 1423 | } else { |
| 1424 | // Materialized condition, compare against 0. |
| 1425 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1426 | if (lhs.IsRegister()) { |
| 1427 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1428 | } else { |
| 1429 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1430 | } |
| 1431 | if (true_target == nullptr) { |
| 1432 | __ j(kEqual, false_target); |
| 1433 | } else { |
| 1434 | __ j(kNotEqual, true_target); |
| 1435 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1436 | } |
| 1437 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1438 | // Condition has not been materialized, use its inputs as the comparison and |
| 1439 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1440 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1441 | |
| 1442 | // If this is a long or FP comparison that has been folded into |
| 1443 | // the HCondition, generate the comparison directly. |
| 1444 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1445 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1446 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1447 | return; |
| 1448 | } |
| 1449 | |
| 1450 | Location lhs = condition->GetLocations()->InAt(0); |
| 1451 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1452 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1453 | if (rhs.IsRegister()) { |
| 1454 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1455 | } else if (rhs.IsConstant()) { |
| 1456 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1457 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1458 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1459 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1460 | } |
| 1461 | if (true_target == nullptr) { |
| 1462 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1463 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1464 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1465 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1466 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1467 | |
| 1468 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1469 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1470 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1471 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1472 | } |
| 1473 | } |
| 1474 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1475 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1476 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1477 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1478 | locations->SetInAt(0, Location::Any()); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1483 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1484 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1485 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1486 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1487 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1488 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1489 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
| 1492 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1493 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1494 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1495 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1496 | locations->SetInAt(0, Location::Any()); |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1501 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1502 | GenerateTestAndBranch<Label>(deoptimize, |
| 1503 | /* condition_input_index */ 0, |
| 1504 | slow_path->GetEntryLabel(), |
| 1505 | /* false_target */ nullptr); |
| 1506 | } |
| 1507 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1508 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1509 | // There are no conditional move instructions for XMMs. |
| 1510 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1511 | return false; |
| 1512 | } |
| 1513 | |
| 1514 | // A FP condition doesn't generate the single CC that we need. |
| 1515 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1516 | HInstruction* condition = select->GetCondition(); |
| 1517 | if (condition->IsCondition()) { |
| 1518 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1519 | if (compare_type == Primitive::kPrimLong || |
| 1520 | Primitive::IsFloatingPointType(compare_type)) { |
| 1521 | return false; |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | // We can generate a CMOV for this Select. |
| 1526 | return true; |
| 1527 | } |
| 1528 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1529 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1530 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1531 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1532 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1533 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1534 | } else { |
| 1535 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1536 | if (SelectCanUseCMOV(select)) { |
| 1537 | if (select->InputAt(1)->IsConstant()) { |
| 1538 | // Cmov can't handle a constant value. |
| 1539 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1540 | } else { |
| 1541 | locations->SetInAt(1, Location::Any()); |
| 1542 | } |
| 1543 | } else { |
| 1544 | locations->SetInAt(1, Location::Any()); |
| 1545 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1546 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1547 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1548 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1549 | } |
| 1550 | locations->SetOut(Location::SameAsFirstInput()); |
| 1551 | } |
| 1552 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1553 | void InstructionCodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 1554 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 1555 | if (rhs.IsConstant()) { |
| 1556 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1557 | codegen_->Compare32BitValue(lhs_reg, value); |
| 1558 | } else if (rhs.IsStackSlot()) { |
| 1559 | __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
| 1560 | } else { |
| 1561 | __ cmpl(lhs_reg, rhs.AsRegister<Register>()); |
| 1562 | } |
| 1563 | } |
| 1564 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1565 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1566 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1567 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1568 | if (SelectCanUseCMOV(select)) { |
| 1569 | // If both the condition and the source types are integer, we can generate |
| 1570 | // a CMOV to implement Select. |
| 1571 | |
| 1572 | HInstruction* select_condition = select->GetCondition(); |
| 1573 | Condition cond = kNotEqual; |
| 1574 | |
| 1575 | // Figure out how to test the 'condition'. |
| 1576 | if (select_condition->IsCondition()) { |
| 1577 | HCondition* condition = select_condition->AsCondition(); |
| 1578 | if (!condition->IsEmittedAtUseSite()) { |
| 1579 | // This was a previously materialized condition. |
| 1580 | // Can we use the existing condition code? |
| 1581 | if (AreEflagsSetFrom(condition, select)) { |
| 1582 | // Materialization was the previous instruction. Condition codes are right. |
| 1583 | cond = X86Condition(condition->GetCondition()); |
| 1584 | } else { |
| 1585 | // No, we have to recreate the condition code. |
| 1586 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1587 | __ testl(cond_reg, cond_reg); |
| 1588 | } |
| 1589 | } else { |
| 1590 | // We can't handle FP or long here. |
| 1591 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1592 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1593 | LocationSummary* cond_locations = condition->GetLocations(); |
| 1594 | GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| 1595 | cond = X86Condition(condition->GetCondition()); |
| 1596 | } |
| 1597 | } else { |
| 1598 | // Must be a boolean condition, which needs to be compared to 0. |
| 1599 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1600 | __ testl(cond_reg, cond_reg); |
| 1601 | } |
| 1602 | |
| 1603 | // If the condition is true, overwrite the output, which already contains false. |
| 1604 | Location false_loc = locations->InAt(0); |
| 1605 | Location true_loc = locations->InAt(1); |
| 1606 | if (select->GetType() == Primitive::kPrimLong) { |
| 1607 | // 64 bit conditional move. |
| 1608 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1609 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1610 | if (true_loc.IsRegisterPair()) { |
| 1611 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1612 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1613 | } else { |
| 1614 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1615 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1616 | } |
| 1617 | } else { |
| 1618 | // 32 bit conditional move. |
| 1619 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1620 | if (true_loc.IsRegister()) { |
| 1621 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1622 | } else { |
| 1623 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1624 | } |
| 1625 | } |
| 1626 | } else { |
| 1627 | NearLabel false_target; |
| 1628 | GenerateTestAndBranch<NearLabel>( |
| 1629 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1630 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1631 | __ Bind(&false_target); |
| 1632 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1633 | } |
| 1634 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1635 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1636 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1637 | } |
| 1638 | |
| 1639 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1640 | codegen_->MaybeRecordNativeDebugInfo(info, info->GetDexPc()); |
| 1641 | } |
| 1642 | |
| 1643 | void CodeGeneratorX86::GenerateNop() { |
| 1644 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1647 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1648 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1651 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1652 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1655 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1656 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1659 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1660 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1663 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1664 | LocationSummary* locations = |
| 1665 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1666 | switch (store->InputAt(1)->GetType()) { |
| 1667 | case Primitive::kPrimBoolean: |
| 1668 | case Primitive::kPrimByte: |
| 1669 | case Primitive::kPrimChar: |
| 1670 | case Primitive::kPrimShort: |
| 1671 | case Primitive::kPrimInt: |
| 1672 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1673 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1674 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1675 | break; |
| 1676 | |
| 1677 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1678 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1679 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1680 | break; |
| 1681 | |
| 1682 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1683 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1684 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1687 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1690 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1691 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1692 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1693 | // Handle the long/FP comparisons made in instruction simplification. |
| 1694 | switch (cond->InputAt(0)->GetType()) { |
| 1695 | case Primitive::kPrimLong: { |
| 1696 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1697 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1698 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1699 | locations->SetOut(Location::RequiresRegister()); |
| 1700 | } |
| 1701 | break; |
| 1702 | } |
| 1703 | case Primitive::kPrimFloat: |
| 1704 | case Primitive::kPrimDouble: { |
| 1705 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1706 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1707 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1708 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1709 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1710 | } else { |
| 1711 | locations->SetInAt(1, Location::Any()); |
| 1712 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1713 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1714 | locations->SetOut(Location::RequiresRegister()); |
| 1715 | } |
| 1716 | break; |
| 1717 | } |
| 1718 | default: |
| 1719 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1720 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1721 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1722 | // We need a byte register. |
| 1723 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1724 | } |
| 1725 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1726 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1729 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1730 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1731 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1732 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1733 | |
| 1734 | LocationSummary* locations = cond->GetLocations(); |
| 1735 | Location lhs = locations->InAt(0); |
| 1736 | Location rhs = locations->InAt(1); |
| 1737 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1738 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1739 | |
| 1740 | switch (cond->InputAt(0)->GetType()) { |
| 1741 | default: { |
| 1742 | // Integer case. |
| 1743 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1744 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1745 | __ xorl(reg, reg); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1746 | GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1747 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1748 | return; |
| 1749 | } |
| 1750 | case Primitive::kPrimLong: |
| 1751 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1752 | break; |
| 1753 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1754 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1755 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1756 | break; |
| 1757 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1758 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1759 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1760 | break; |
| 1761 | } |
| 1762 | |
| 1763 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1764 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1765 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1766 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1767 | __ Bind(&false_label); |
| 1768 | __ xorl(reg, reg); |
| 1769 | __ jmp(&done_label); |
| 1770 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1771 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1772 | __ Bind(&true_label); |
| 1773 | __ movl(reg, Immediate(1)); |
| 1774 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1778 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1786 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1798 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1802 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1806 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1810 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1814 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1818 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1822 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1823 | } |
| 1824 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1825 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1826 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1830 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1834 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1838 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1842 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1846 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1850 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1854 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1857 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1858 | LocationSummary* locations = |
| 1859 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1860 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1863 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1864 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1867 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1868 | LocationSummary* locations = |
| 1869 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1870 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1871 | } |
| 1872 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1873 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1874 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1877 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1878 | LocationSummary* locations = |
| 1879 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1880 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1881 | } |
| 1882 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1883 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1884 | // Will be generated at use site. |
| 1885 | } |
| 1886 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1887 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1888 | LocationSummary* locations = |
| 1889 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1890 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1891 | } |
| 1892 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1893 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1894 | // Will be generated at use site. |
| 1895 | } |
| 1896 | |
| 1897 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1898 | LocationSummary* locations = |
| 1899 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1900 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1901 | } |
| 1902 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1903 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1904 | // Will be generated at use site. |
| 1905 | } |
| 1906 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1907 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1908 | memory_barrier->SetLocations(nullptr); |
| 1909 | } |
| 1910 | |
| 1911 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1912 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1913 | } |
| 1914 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1915 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1916 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1919 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1920 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1923 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1924 | LocationSummary* locations = |
| 1925 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1926 | switch (ret->InputAt(0)->GetType()) { |
| 1927 | case Primitive::kPrimBoolean: |
| 1928 | case Primitive::kPrimByte: |
| 1929 | case Primitive::kPrimChar: |
| 1930 | case Primitive::kPrimShort: |
| 1931 | case Primitive::kPrimInt: |
| 1932 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1933 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1934 | break; |
| 1935 | |
| 1936 | case Primitive::kPrimLong: |
| 1937 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1938 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1939 | break; |
| 1940 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1941 | case Primitive::kPrimFloat: |
| 1942 | case Primitive::kPrimDouble: |
| 1943 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1944 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1945 | break; |
| 1946 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1947 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1948 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1949 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1952 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1953 | if (kIsDebugBuild) { |
| 1954 | switch (ret->InputAt(0)->GetType()) { |
| 1955 | case Primitive::kPrimBoolean: |
| 1956 | case Primitive::kPrimByte: |
| 1957 | case Primitive::kPrimChar: |
| 1958 | case Primitive::kPrimShort: |
| 1959 | case Primitive::kPrimInt: |
| 1960 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1961 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1962 | break; |
| 1963 | |
| 1964 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1965 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1966 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1967 | break; |
| 1968 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1969 | case Primitive::kPrimFloat: |
| 1970 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1971 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1972 | break; |
| 1973 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1974 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1975 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1976 | } |
| 1977 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1978 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1981 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1982 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1983 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1984 | // the method_idx. |
| 1985 | HandleInvoke(invoke); |
| 1986 | } |
| 1987 | |
| 1988 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1989 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1990 | } |
| 1991 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1992 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1993 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1994 | // art::PrepareForRegisterAllocation. |
| 1995 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1996 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1997 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1998 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1999 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2000 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2001 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2002 | return; |
| 2003 | } |
| 2004 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2005 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2006 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2007 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 2008 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2009 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2010 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2011 | } |
| 2012 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2013 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2014 | if (invoke->GetLocations()->Intrinsified()) { |
| 2015 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2016 | intrinsic.Dispatch(invoke); |
| 2017 | return true; |
| 2018 | } |
| 2019 | return false; |
| 2020 | } |
| 2021 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2022 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2023 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 2024 | // art::PrepareForRegisterAllocation. |
| 2025 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2026 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2027 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2028 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2029 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2030 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2031 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2032 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2033 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2034 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2038 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2039 | if (intrinsic.TryDispatch(invoke)) { |
| 2040 | return; |
| 2041 | } |
| 2042 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2043 | HandleInvoke(invoke); |
| 2044 | } |
| 2045 | |
| 2046 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2047 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2048 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2051 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2052 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2053 | return; |
| 2054 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2055 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2056 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2057 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2058 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2061 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2062 | // This call to HandleInvoke allocates a temporary (core) register |
| 2063 | // which is also used to transfer the hidden argument from FP to |
| 2064 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2065 | HandleInvoke(invoke); |
| 2066 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2067 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2071 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2072 | LocationSummary* locations = invoke->GetLocations(); |
| 2073 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2074 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2075 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2076 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2077 | Location receiver = locations->InAt(0); |
| 2078 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2079 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2080 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2081 | // won't be modified thereafter, before the `call` instruction. |
| 2082 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2083 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2084 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2085 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2086 | if (receiver.IsStackSlot()) { |
| 2087 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2088 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2089 | __ movl(temp, Address(temp, class_offset)); |
| 2090 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2091 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2092 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2093 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2094 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2095 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2096 | // emit a read barrier for the previous class reference load. |
| 2097 | // However this is not required in practice, as this is an |
| 2098 | // intermediate/temporary reference and because the current |
| 2099 | // concurrent copying collector keeps the from-space memory |
| 2100 | // intact/accessible until the end of the marking phase (the |
| 2101 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2102 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2103 | // temp = temp->GetImtEntryAt(method_offset); |
| 2104 | __ movl(temp, Address(temp, method_offset)); |
| 2105 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2106 | __ call(Address(temp, |
| 2107 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2108 | |
| 2109 | DCHECK(!codegen_->IsLeafMethod()); |
| 2110 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2111 | } |
| 2112 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2113 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2114 | LocationSummary* locations = |
| 2115 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2116 | switch (neg->GetResultType()) { |
| 2117 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2118 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2119 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2120 | locations->SetOut(Location::SameAsFirstInput()); |
| 2121 | break; |
| 2122 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2123 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2124 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2125 | locations->SetOut(Location::SameAsFirstInput()); |
| 2126 | locations->AddTemp(Location::RequiresRegister()); |
| 2127 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2128 | break; |
| 2129 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2130 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2131 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2132 | locations->SetOut(Location::SameAsFirstInput()); |
| 2133 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2134 | break; |
| 2135 | |
| 2136 | default: |
| 2137 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2138 | } |
| 2139 | } |
| 2140 | |
| 2141 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2142 | LocationSummary* locations = neg->GetLocations(); |
| 2143 | Location out = locations->Out(); |
| 2144 | Location in = locations->InAt(0); |
| 2145 | switch (neg->GetResultType()) { |
| 2146 | case Primitive::kPrimInt: |
| 2147 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2148 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2149 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2150 | break; |
| 2151 | |
| 2152 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2153 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2154 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2155 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2156 | // Negation is similar to subtraction from zero. The least |
| 2157 | // significant byte triggers a borrow when it is different from |
| 2158 | // zero; to take it into account, add 1 to the most significant |
| 2159 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2160 | // operation. |
| 2161 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2162 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2163 | break; |
| 2164 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2165 | case Primitive::kPrimFloat: { |
| 2166 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2167 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2168 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2169 | // Implement float negation with an exclusive or with value |
| 2170 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2171 | // single-precision floating-point number). |
| 2172 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2173 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2174 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2175 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2176 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2177 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2178 | case Primitive::kPrimDouble: { |
| 2179 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2180 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2181 | // Implement double negation with an exclusive or with value |
| 2182 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2183 | // a double-precision floating-point number). |
| 2184 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2185 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2186 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2187 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2188 | |
| 2189 | default: |
| 2190 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2191 | } |
| 2192 | } |
| 2193 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2194 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2195 | LocationSummary* locations = |
| 2196 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2197 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2198 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2199 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2200 | locations->SetOut(Location::SameAsFirstInput()); |
| 2201 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2202 | } |
| 2203 | |
| 2204 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2205 | LocationSummary* locations = neg->GetLocations(); |
| 2206 | Location out = locations->Out(); |
| 2207 | DCHECK(locations->InAt(0).Equals(out)); |
| 2208 | |
| 2209 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2210 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2211 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2212 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2213 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2214 | } else { |
| 2215 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2216 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2217 | } |
| 2218 | } |
| 2219 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2220 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2221 | Primitive::Type result_type = conversion->GetResultType(); |
| 2222 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2223 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2224 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2225 | // The float-to-long and double-to-long type conversions rely on a |
| 2226 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2227 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2228 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2229 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2230 | ? LocationSummary::kCall |
| 2231 | : LocationSummary::kNoCall; |
| 2232 | LocationSummary* locations = |
| 2233 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2234 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2235 | // The Java language does not allow treating boolean as an integral type but |
| 2236 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2237 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2238 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2239 | case Primitive::kPrimByte: |
| 2240 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2241 | case Primitive::kPrimLong: { |
| 2242 | // Type conversion from long to byte is a result of code transformations. |
| 2243 | HInstruction* input = conversion->InputAt(0); |
| 2244 | Location input_location = input->IsConstant() |
| 2245 | ? Location::ConstantLocation(input->AsConstant()) |
| 2246 | : Location::RegisterPairLocation(EAX, EDX); |
| 2247 | locations->SetInAt(0, input_location); |
| 2248 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2249 | // the validation of the linear scan implementation |
| 2250 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2251 | break; |
| 2252 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2253 | case Primitive::kPrimBoolean: |
| 2254 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2255 | case Primitive::kPrimShort: |
| 2256 | case Primitive::kPrimInt: |
| 2257 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2258 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2259 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2260 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2261 | // the validation of the linear scan implementation |
| 2262 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2263 | break; |
| 2264 | |
| 2265 | default: |
| 2266 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2267 | << " to " << result_type; |
| 2268 | } |
| 2269 | break; |
| 2270 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2271 | case Primitive::kPrimShort: |
| 2272 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2273 | case Primitive::kPrimLong: |
| 2274 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2275 | case Primitive::kPrimBoolean: |
| 2276 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2277 | case Primitive::kPrimByte: |
| 2278 | case Primitive::kPrimInt: |
| 2279 | case Primitive::kPrimChar: |
| 2280 | // Processing a Dex `int-to-short' instruction. |
| 2281 | locations->SetInAt(0, Location::Any()); |
| 2282 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2283 | break; |
| 2284 | |
| 2285 | default: |
| 2286 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2287 | << " to " << result_type; |
| 2288 | } |
| 2289 | break; |
| 2290 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2291 | case Primitive::kPrimInt: |
| 2292 | switch (input_type) { |
| 2293 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2294 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2295 | locations->SetInAt(0, Location::Any()); |
| 2296 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2297 | break; |
| 2298 | |
| 2299 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2300 | // Processing a Dex `float-to-int' instruction. |
| 2301 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2302 | locations->SetOut(Location::RequiresRegister()); |
| 2303 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2304 | break; |
| 2305 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2306 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2307 | // Processing a Dex `double-to-int' instruction. |
| 2308 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2309 | locations->SetOut(Location::RequiresRegister()); |
| 2310 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2311 | break; |
| 2312 | |
| 2313 | default: |
| 2314 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2315 | << " to " << result_type; |
| 2316 | } |
| 2317 | break; |
| 2318 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2319 | case Primitive::kPrimLong: |
| 2320 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2321 | case Primitive::kPrimBoolean: |
| 2322 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2323 | case Primitive::kPrimByte: |
| 2324 | case Primitive::kPrimShort: |
| 2325 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2326 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2327 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2328 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2329 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2330 | break; |
| 2331 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2332 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2333 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2334 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2335 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2336 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2337 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2338 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2339 | // The runtime helper puts the result in EAX, EDX. |
| 2340 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2341 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2342 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2343 | |
| 2344 | default: |
| 2345 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2346 | << " to " << result_type; |
| 2347 | } |
| 2348 | break; |
| 2349 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2350 | case Primitive::kPrimChar: |
| 2351 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2352 | case Primitive::kPrimLong: |
| 2353 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2354 | case Primitive::kPrimBoolean: |
| 2355 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2356 | case Primitive::kPrimByte: |
| 2357 | case Primitive::kPrimShort: |
| 2358 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2359 | // Processing a Dex `int-to-char' instruction. |
| 2360 | locations->SetInAt(0, Location::Any()); |
| 2361 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2362 | break; |
| 2363 | |
| 2364 | default: |
| 2365 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2366 | << " to " << result_type; |
| 2367 | } |
| 2368 | break; |
| 2369 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2370 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2371 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2372 | case Primitive::kPrimBoolean: |
| 2373 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2374 | case Primitive::kPrimByte: |
| 2375 | case Primitive::kPrimShort: |
| 2376 | case Primitive::kPrimInt: |
| 2377 | case Primitive::kPrimChar: |
| 2378 | // Processing a Dex `int-to-float' instruction. |
| 2379 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2380 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2381 | break; |
| 2382 | |
| 2383 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2384 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2385 | locations->SetInAt(0, Location::Any()); |
| 2386 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2387 | break; |
| 2388 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2389 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2390 | // Processing a Dex `double-to-float' instruction. |
| 2391 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2392 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2393 | break; |
| 2394 | |
| 2395 | default: |
| 2396 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2397 | << " to " << result_type; |
| 2398 | }; |
| 2399 | break; |
| 2400 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2401 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2402 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2403 | case Primitive::kPrimBoolean: |
| 2404 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimByte: |
| 2406 | case Primitive::kPrimShort: |
| 2407 | case Primitive::kPrimInt: |
| 2408 | case Primitive::kPrimChar: |
| 2409 | // Processing a Dex `int-to-double' instruction. |
| 2410 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2411 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2412 | break; |
| 2413 | |
| 2414 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2415 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2416 | locations->SetInAt(0, Location::Any()); |
| 2417 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2418 | break; |
| 2419 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2420 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2421 | // Processing a Dex `float-to-double' instruction. |
| 2422 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2423 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2424 | break; |
| 2425 | |
| 2426 | default: |
| 2427 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2428 | << " to " << result_type; |
| 2429 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2430 | break; |
| 2431 | |
| 2432 | default: |
| 2433 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2434 | << " to " << result_type; |
| 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2439 | LocationSummary* locations = conversion->GetLocations(); |
| 2440 | Location out = locations->Out(); |
| 2441 | Location in = locations->InAt(0); |
| 2442 | Primitive::Type result_type = conversion->GetResultType(); |
| 2443 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2444 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2445 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2446 | case Primitive::kPrimByte: |
| 2447 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2448 | case Primitive::kPrimLong: |
| 2449 | // Type conversion from long to byte is a result of code transformations. |
| 2450 | if (in.IsRegisterPair()) { |
| 2451 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2452 | } else { |
| 2453 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2454 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2455 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2456 | } |
| 2457 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2458 | case Primitive::kPrimBoolean: |
| 2459 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2460 | case Primitive::kPrimShort: |
| 2461 | case Primitive::kPrimInt: |
| 2462 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2463 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2464 | if (in.IsRegister()) { |
| 2465 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2466 | } else { |
| 2467 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2468 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2469 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2470 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2471 | break; |
| 2472 | |
| 2473 | default: |
| 2474 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2475 | << " to " << result_type; |
| 2476 | } |
| 2477 | break; |
| 2478 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2479 | case Primitive::kPrimShort: |
| 2480 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2481 | case Primitive::kPrimLong: |
| 2482 | // Type conversion from long to short is a result of code transformations. |
| 2483 | if (in.IsRegisterPair()) { |
| 2484 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2485 | } else if (in.IsDoubleStackSlot()) { |
| 2486 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2487 | } else { |
| 2488 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2489 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2490 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2491 | } |
| 2492 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2493 | case Primitive::kPrimBoolean: |
| 2494 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2495 | case Primitive::kPrimByte: |
| 2496 | case Primitive::kPrimInt: |
| 2497 | case Primitive::kPrimChar: |
| 2498 | // Processing a Dex `int-to-short' instruction. |
| 2499 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2500 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2501 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2502 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2503 | } else { |
| 2504 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2505 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2506 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2507 | } |
| 2508 | break; |
| 2509 | |
| 2510 | default: |
| 2511 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2512 | << " to " << result_type; |
| 2513 | } |
| 2514 | break; |
| 2515 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2516 | case Primitive::kPrimInt: |
| 2517 | switch (input_type) { |
| 2518 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2519 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2520 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2521 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2522 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2523 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2524 | } else { |
| 2525 | DCHECK(in.IsConstant()); |
| 2526 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2527 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2528 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2529 | } |
| 2530 | break; |
| 2531 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2532 | case Primitive::kPrimFloat: { |
| 2533 | // Processing a Dex `float-to-int' instruction. |
| 2534 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2535 | Register output = out.AsRegister<Register>(); |
| 2536 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2537 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2538 | |
| 2539 | __ movl(output, Immediate(kPrimIntMax)); |
| 2540 | // temp = int-to-float(output) |
| 2541 | __ cvtsi2ss(temp, output); |
| 2542 | // if input >= temp goto done |
| 2543 | __ comiss(input, temp); |
| 2544 | __ j(kAboveEqual, &done); |
| 2545 | // if input == NaN goto nan |
| 2546 | __ j(kUnordered, &nan); |
| 2547 | // output = float-to-int-truncate(input) |
| 2548 | __ cvttss2si(output, input); |
| 2549 | __ jmp(&done); |
| 2550 | __ Bind(&nan); |
| 2551 | // output = 0 |
| 2552 | __ xorl(output, output); |
| 2553 | __ Bind(&done); |
| 2554 | break; |
| 2555 | } |
| 2556 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2557 | case Primitive::kPrimDouble: { |
| 2558 | // Processing a Dex `double-to-int' instruction. |
| 2559 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2560 | Register output = out.AsRegister<Register>(); |
| 2561 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2562 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2563 | |
| 2564 | __ movl(output, Immediate(kPrimIntMax)); |
| 2565 | // temp = int-to-double(output) |
| 2566 | __ cvtsi2sd(temp, output); |
| 2567 | // if input >= temp goto done |
| 2568 | __ comisd(input, temp); |
| 2569 | __ j(kAboveEqual, &done); |
| 2570 | // if input == NaN goto nan |
| 2571 | __ j(kUnordered, &nan); |
| 2572 | // output = double-to-int-truncate(input) |
| 2573 | __ cvttsd2si(output, input); |
| 2574 | __ jmp(&done); |
| 2575 | __ Bind(&nan); |
| 2576 | // output = 0 |
| 2577 | __ xorl(output, output); |
| 2578 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2579 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2580 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2581 | |
| 2582 | default: |
| 2583 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2584 | << " to " << result_type; |
| 2585 | } |
| 2586 | break; |
| 2587 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2588 | case Primitive::kPrimLong: |
| 2589 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2590 | case Primitive::kPrimBoolean: |
| 2591 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2592 | case Primitive::kPrimByte: |
| 2593 | case Primitive::kPrimShort: |
| 2594 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2595 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2596 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2597 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2598 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2599 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2600 | __ cdq(); |
| 2601 | break; |
| 2602 | |
| 2603 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2604 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2605 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2606 | conversion, |
| 2607 | conversion->GetDexPc(), |
| 2608 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2609 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2610 | break; |
| 2611 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2612 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2613 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2614 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2615 | conversion, |
| 2616 | conversion->GetDexPc(), |
| 2617 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2618 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2619 | break; |
| 2620 | |
| 2621 | default: |
| 2622 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2623 | << " to " << result_type; |
| 2624 | } |
| 2625 | break; |
| 2626 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2627 | case Primitive::kPrimChar: |
| 2628 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2629 | case Primitive::kPrimLong: |
| 2630 | // Type conversion from long to short is a result of code transformations. |
| 2631 | if (in.IsRegisterPair()) { |
| 2632 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2633 | } else if (in.IsDoubleStackSlot()) { |
| 2634 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2635 | } else { |
| 2636 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2637 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2638 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2639 | } |
| 2640 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2641 | case Primitive::kPrimBoolean: |
| 2642 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2643 | case Primitive::kPrimByte: |
| 2644 | case Primitive::kPrimShort: |
| 2645 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2646 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2647 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2648 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2649 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2650 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2651 | } else { |
| 2652 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2653 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2654 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2655 | } |
| 2656 | break; |
| 2657 | |
| 2658 | default: |
| 2659 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2660 | << " to " << result_type; |
| 2661 | } |
| 2662 | break; |
| 2663 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2664 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2665 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2666 | case Primitive::kPrimBoolean: |
| 2667 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2668 | case Primitive::kPrimByte: |
| 2669 | case Primitive::kPrimShort: |
| 2670 | case Primitive::kPrimInt: |
| 2671 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2672 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2673 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2674 | break; |
| 2675 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2676 | case Primitive::kPrimLong: { |
| 2677 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2678 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2679 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2680 | // Create stack space for the call to |
| 2681 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2682 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2683 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2684 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2685 | __ subl(ESP, Immediate(adjustment)); |
| 2686 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2687 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2688 | // Load the value to the FP stack, using temporaries if needed. |
| 2689 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2690 | |
| 2691 | if (out.IsStackSlot()) { |
| 2692 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2693 | } else { |
| 2694 | __ fstps(Address(ESP, 0)); |
| 2695 | Location stack_temp = Location::StackSlot(0); |
| 2696 | codegen_->Move32(out, stack_temp); |
| 2697 | } |
| 2698 | |
| 2699 | // Remove the temporary stack space we allocated. |
| 2700 | if (adjustment != 0) { |
| 2701 | __ addl(ESP, Immediate(adjustment)); |
| 2702 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2703 | break; |
| 2704 | } |
| 2705 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2706 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2707 | // Processing a Dex `double-to-float' instruction. |
| 2708 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2709 | break; |
| 2710 | |
| 2711 | default: |
| 2712 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2713 | << " to " << result_type; |
| 2714 | }; |
| 2715 | break; |
| 2716 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2717 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2718 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2719 | case Primitive::kPrimBoolean: |
| 2720 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2721 | case Primitive::kPrimByte: |
| 2722 | case Primitive::kPrimShort: |
| 2723 | case Primitive::kPrimInt: |
| 2724 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2725 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2726 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2727 | break; |
| 2728 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2729 | case Primitive::kPrimLong: { |
| 2730 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2731 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2732 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2733 | // Create stack space for the call to |
| 2734 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2735 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2736 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2737 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2738 | __ subl(ESP, Immediate(adjustment)); |
| 2739 | } |
| 2740 | |
| 2741 | // Load the value to the FP stack, using temporaries if needed. |
| 2742 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2743 | |
| 2744 | if (out.IsDoubleStackSlot()) { |
| 2745 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2746 | } else { |
| 2747 | __ fstpl(Address(ESP, 0)); |
| 2748 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2749 | codegen_->Move64(out, stack_temp); |
| 2750 | } |
| 2751 | |
| 2752 | // Remove the temporary stack space we allocated. |
| 2753 | if (adjustment != 0) { |
| 2754 | __ addl(ESP, Immediate(adjustment)); |
| 2755 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2756 | break; |
| 2757 | } |
| 2758 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2759 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2760 | // Processing a Dex `float-to-double' instruction. |
| 2761 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2762 | break; |
| 2763 | |
| 2764 | default: |
| 2765 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2766 | << " to " << result_type; |
| 2767 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2768 | break; |
| 2769 | |
| 2770 | default: |
| 2771 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2772 | << " to " << result_type; |
| 2773 | } |
| 2774 | } |
| 2775 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2776 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2777 | LocationSummary* locations = |
| 2778 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2779 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2780 | case Primitive::kPrimInt: { |
| 2781 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2782 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2783 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2784 | break; |
| 2785 | } |
| 2786 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2787 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2788 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2789 | locations->SetInAt(1, Location::Any()); |
| 2790 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2791 | break; |
| 2792 | } |
| 2793 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2794 | case Primitive::kPrimFloat: |
| 2795 | case Primitive::kPrimDouble: { |
| 2796 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2797 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2798 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2799 | } else if (add->InputAt(1)->IsConstant()) { |
| 2800 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2801 | } else { |
| 2802 | locations->SetInAt(1, Location::Any()); |
| 2803 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2804 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2805 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2806 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2807 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2808 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2809 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2810 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2811 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2815 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2816 | Location first = locations->InAt(0); |
| 2817 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2818 | Location out = locations->Out(); |
| 2819 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2820 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2821 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2822 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2823 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2824 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2825 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2826 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2827 | } else { |
| 2828 | __ leal(out.AsRegister<Register>(), Address( |
| 2829 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2830 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2831 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2832 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2833 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2834 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2835 | } else { |
| 2836 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2837 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2838 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2839 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2840 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2841 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2842 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2846 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2847 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2848 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2849 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2850 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2851 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2852 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2853 | } else { |
| 2854 | DCHECK(second.IsConstant()) << second; |
| 2855 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2856 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2857 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2858 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2859 | break; |
| 2860 | } |
| 2861 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2862 | case Primitive::kPrimFloat: { |
| 2863 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2864 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2865 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2866 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2867 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2868 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2869 | codegen_->LiteralFloatAddress( |
| 2870 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2871 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2872 | } else { |
| 2873 | DCHECK(second.IsStackSlot()); |
| 2874 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2875 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2876 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | case Primitive::kPrimDouble: { |
| 2880 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2881 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2882 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2883 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2884 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2885 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2886 | codegen_->LiteralDoubleAddress( |
| 2887 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2888 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2889 | } else { |
| 2890 | DCHECK(second.IsDoubleStackSlot()); |
| 2891 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2892 | } |
| 2893 | break; |
| 2894 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2895 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2896 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2897 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2898 | } |
| 2899 | } |
| 2900 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2901 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2902 | LocationSummary* locations = |
| 2903 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2904 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2905 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2906 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2907 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2908 | locations->SetInAt(1, Location::Any()); |
| 2909 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2910 | break; |
| 2911 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2912 | case Primitive::kPrimFloat: |
| 2913 | case Primitive::kPrimDouble: { |
| 2914 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2915 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2916 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2917 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2918 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2919 | } else { |
| 2920 | locations->SetInAt(1, Location::Any()); |
| 2921 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2922 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2923 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2924 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2925 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2926 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2927 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2928 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2932 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2933 | Location first = locations->InAt(0); |
| 2934 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2935 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2936 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2937 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2938 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2939 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2940 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2941 | __ subl(first.AsRegister<Register>(), |
| 2942 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2943 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2944 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2945 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2946 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2950 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2951 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2952 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2953 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2954 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2955 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2956 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2957 | } else { |
| 2958 | DCHECK(second.IsConstant()) << second; |
| 2959 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2960 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2961 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2962 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2963 | break; |
| 2964 | } |
| 2965 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2966 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2967 | if (second.IsFpuRegister()) { |
| 2968 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2969 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2970 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2971 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2972 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2973 | codegen_->LiteralFloatAddress( |
| 2974 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2975 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2976 | } else { |
| 2977 | DCHECK(second.IsStackSlot()); |
| 2978 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2979 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2980 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2984 | if (second.IsFpuRegister()) { |
| 2985 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2986 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2987 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2988 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2989 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2990 | codegen_->LiteralDoubleAddress( |
| 2991 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2992 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2993 | } else { |
| 2994 | DCHECK(second.IsDoubleStackSlot()); |
| 2995 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2996 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2997 | break; |
| 2998 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2999 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3000 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3001 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3002 | } |
| 3003 | } |
| 3004 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3005 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 3006 | LocationSummary* locations = |
| 3007 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 3008 | switch (mul->GetResultType()) { |
| 3009 | case Primitive::kPrimInt: |
| 3010 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3011 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3012 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3013 | // Can use 3 operand multiply. |
| 3014 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3015 | } else { |
| 3016 | locations->SetOut(Location::SameAsFirstInput()); |
| 3017 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3018 | break; |
| 3019 | case Primitive::kPrimLong: { |
| 3020 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3021 | locations->SetInAt(1, Location::Any()); |
| 3022 | locations->SetOut(Location::SameAsFirstInput()); |
| 3023 | // Needed for imul on 32bits with 64bits output. |
| 3024 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 3025 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 3026 | break; |
| 3027 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3028 | case Primitive::kPrimFloat: |
| 3029 | case Primitive::kPrimDouble: { |
| 3030 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3031 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3032 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3033 | } else if (mul->InputAt(1)->IsConstant()) { |
| 3034 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3035 | } else { |
| 3036 | locations->SetInAt(1, Location::Any()); |
| 3037 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3038 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3039 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3040 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3041 | |
| 3042 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3043 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 3048 | LocationSummary* locations = mul->GetLocations(); |
| 3049 | Location first = locations->InAt(0); |
| 3050 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3051 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3052 | |
| 3053 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3054 | case Primitive::kPrimInt: |
| 3055 | // The constant may have ended up in a register, so test explicitly to avoid |
| 3056 | // problems where the output may not be the same as the first operand. |
| 3057 | if (mul->InputAt(1)->IsIntConstant()) { |
| 3058 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 3059 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3060 | } else if (second.IsRegister()) { |
| 3061 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3062 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3063 | } else { |
| 3064 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3065 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3066 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3067 | } |
| 3068 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3069 | |
| 3070 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3071 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3072 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3073 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3074 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3075 | |
| 3076 | DCHECK_EQ(EAX, eax); |
| 3077 | DCHECK_EQ(EDX, edx); |
| 3078 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3079 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3080 | // output: in1 |
| 3081 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3082 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3083 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3084 | if (second.IsConstant()) { |
| 3085 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3086 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3087 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3088 | int32_t low_value = Low32Bits(value); |
| 3089 | int32_t high_value = High32Bits(value); |
| 3090 | Immediate low(low_value); |
| 3091 | Immediate high(high_value); |
| 3092 | |
| 3093 | __ movl(eax, high); |
| 3094 | // eax <- in1.lo * in2.hi |
| 3095 | __ imull(eax, in1_lo); |
| 3096 | // in1.hi <- in1.hi * in2.lo |
| 3097 | __ imull(in1_hi, low); |
| 3098 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3099 | __ addl(in1_hi, eax); |
| 3100 | // move in2_lo to eax to prepare for double precision |
| 3101 | __ movl(eax, low); |
| 3102 | // edx:eax <- in1.lo * in2.lo |
| 3103 | __ mull(in1_lo); |
| 3104 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3105 | __ addl(in1_hi, edx); |
| 3106 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3107 | __ movl(in1_lo, eax); |
| 3108 | } else if (second.IsRegisterPair()) { |
| 3109 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3110 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3111 | |
| 3112 | __ movl(eax, in2_hi); |
| 3113 | // eax <- in1.lo * in2.hi |
| 3114 | __ imull(eax, in1_lo); |
| 3115 | // in1.hi <- in1.hi * in2.lo |
| 3116 | __ imull(in1_hi, in2_lo); |
| 3117 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3118 | __ addl(in1_hi, eax); |
| 3119 | // move in1_lo to eax to prepare for double precision |
| 3120 | __ movl(eax, in1_lo); |
| 3121 | // edx:eax <- in1.lo * in2.lo |
| 3122 | __ mull(in2_lo); |
| 3123 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3124 | __ addl(in1_hi, edx); |
| 3125 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3126 | __ movl(in1_lo, eax); |
| 3127 | } else { |
| 3128 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3129 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3130 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3131 | |
| 3132 | __ movl(eax, in2_hi); |
| 3133 | // eax <- in1.lo * in2.hi |
| 3134 | __ imull(eax, in1_lo); |
| 3135 | // in1.hi <- in1.hi * in2.lo |
| 3136 | __ imull(in1_hi, in2_lo); |
| 3137 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3138 | __ addl(in1_hi, eax); |
| 3139 | // move in1_lo to eax to prepare for double precision |
| 3140 | __ movl(eax, in1_lo); |
| 3141 | // edx:eax <- in1.lo * in2.lo |
| 3142 | __ mull(in2_lo); |
| 3143 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3144 | __ addl(in1_hi, edx); |
| 3145 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3146 | __ movl(in1_lo, eax); |
| 3147 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3148 | |
| 3149 | break; |
| 3150 | } |
| 3151 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3152 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3153 | DCHECK(first.Equals(locations->Out())); |
| 3154 | if (second.IsFpuRegister()) { |
| 3155 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3156 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3157 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3158 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3159 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3160 | codegen_->LiteralFloatAddress( |
| 3161 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3162 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3163 | } else { |
| 3164 | DCHECK(second.IsStackSlot()); |
| 3165 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3166 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3167 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3171 | DCHECK(first.Equals(locations->Out())); |
| 3172 | if (second.IsFpuRegister()) { |
| 3173 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3174 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3175 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3176 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3177 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3178 | codegen_->LiteralDoubleAddress( |
| 3179 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3180 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3181 | } else { |
| 3182 | DCHECK(second.IsDoubleStackSlot()); |
| 3183 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3184 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3185 | break; |
| 3186 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3187 | |
| 3188 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3189 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3193 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3194 | uint32_t temp_offset, |
| 3195 | uint32_t stack_adjustment, |
| 3196 | bool is_fp, |
| 3197 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3198 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3199 | DCHECK(!is_wide); |
| 3200 | if (is_fp) { |
| 3201 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3202 | } else { |
| 3203 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3204 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3205 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3206 | DCHECK(is_wide); |
| 3207 | if (is_fp) { |
| 3208 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3209 | } else { |
| 3210 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3211 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3212 | } else { |
| 3213 | // 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] | 3214 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3215 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3216 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3217 | if (is_fp) { |
| 3218 | __ flds(Address(ESP, temp_offset)); |
| 3219 | } else { |
| 3220 | __ filds(Address(ESP, temp_offset)); |
| 3221 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3222 | } else { |
| 3223 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3224 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3225 | if (is_fp) { |
| 3226 | __ fldl(Address(ESP, temp_offset)); |
| 3227 | } else { |
| 3228 | __ fildl(Address(ESP, temp_offset)); |
| 3229 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3230 | } |
| 3231 | } |
| 3232 | } |
| 3233 | |
| 3234 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3235 | Primitive::Type type = rem->GetResultType(); |
| 3236 | bool is_float = type == Primitive::kPrimFloat; |
| 3237 | size_t elem_size = Primitive::ComponentSize(type); |
| 3238 | LocationSummary* locations = rem->GetLocations(); |
| 3239 | Location first = locations->InAt(0); |
| 3240 | Location second = locations->InAt(1); |
| 3241 | Location out = locations->Out(); |
| 3242 | |
| 3243 | // Create stack space for 2 elements. |
| 3244 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3245 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3246 | |
| 3247 | // 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] | 3248 | const bool is_wide = !is_float; |
| 3249 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3250 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3251 | |
| 3252 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3253 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3254 | __ Bind(&retry); |
| 3255 | __ fprem(); |
| 3256 | |
| 3257 | // Move FP status to AX. |
| 3258 | __ fstsw(); |
| 3259 | |
| 3260 | // And see if the argument reduction is complete. This is signaled by the |
| 3261 | // C2 FPU flag bit set to 0. |
| 3262 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3263 | __ j(kNotEqual, &retry); |
| 3264 | |
| 3265 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3266 | // Store FP top of stack to real stack. |
| 3267 | if (is_float) { |
| 3268 | __ fsts(Address(ESP, 0)); |
| 3269 | } else { |
| 3270 | __ fstl(Address(ESP, 0)); |
| 3271 | } |
| 3272 | |
| 3273 | // Pop the 2 items from the FP stack. |
| 3274 | __ fucompp(); |
| 3275 | |
| 3276 | // Load the value from the stack into an XMM register. |
| 3277 | DCHECK(out.IsFpuRegister()) << out; |
| 3278 | if (is_float) { |
| 3279 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3280 | } else { |
| 3281 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3282 | } |
| 3283 | |
| 3284 | // And remove the temporary stack space we allocated. |
| 3285 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3286 | } |
| 3287 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3288 | |
| 3289 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3290 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3291 | |
| 3292 | LocationSummary* locations = instruction->GetLocations(); |
| 3293 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3294 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3295 | |
| 3296 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3297 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3298 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3299 | |
| 3300 | DCHECK(imm == 1 || imm == -1); |
| 3301 | |
| 3302 | if (instruction->IsRem()) { |
| 3303 | __ xorl(out_register, out_register); |
| 3304 | } else { |
| 3305 | __ movl(out_register, input_register); |
| 3306 | if (imm == -1) { |
| 3307 | __ negl(out_register); |
| 3308 | } |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3313 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3314 | LocationSummary* locations = instruction->GetLocations(); |
| 3315 | |
| 3316 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3317 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3318 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3319 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3320 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3321 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3322 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3323 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3324 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3325 | __ testl(input_register, input_register); |
| 3326 | __ cmovl(kGreaterEqual, num, input_register); |
| 3327 | int shift = CTZ(imm); |
| 3328 | __ sarl(num, Immediate(shift)); |
| 3329 | |
| 3330 | if (imm < 0) { |
| 3331 | __ negl(num); |
| 3332 | } |
| 3333 | |
| 3334 | __ movl(out_register, num); |
| 3335 | } |
| 3336 | |
| 3337 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3338 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3339 | |
| 3340 | LocationSummary* locations = instruction->GetLocations(); |
| 3341 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3342 | |
| 3343 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3344 | Register out = locations->Out().AsRegister<Register>(); |
| 3345 | Register num; |
| 3346 | Register edx; |
| 3347 | |
| 3348 | if (instruction->IsDiv()) { |
| 3349 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3350 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3351 | } else { |
| 3352 | edx = locations->Out().AsRegister<Register>(); |
| 3353 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3354 | } |
| 3355 | |
| 3356 | DCHECK_EQ(EAX, eax); |
| 3357 | DCHECK_EQ(EDX, edx); |
| 3358 | if (instruction->IsDiv()) { |
| 3359 | DCHECK_EQ(EAX, out); |
| 3360 | } else { |
| 3361 | DCHECK_EQ(EDX, out); |
| 3362 | } |
| 3363 | |
| 3364 | int64_t magic; |
| 3365 | int shift; |
| 3366 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3367 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3368 | NearLabel ndiv; |
| 3369 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3370 | // If numerator is 0, the result is 0, no computation needed. |
| 3371 | __ testl(eax, eax); |
| 3372 | __ j(kNotEqual, &ndiv); |
| 3373 | |
| 3374 | __ xorl(out, out); |
| 3375 | __ jmp(&end); |
| 3376 | |
| 3377 | __ Bind(&ndiv); |
| 3378 | |
| 3379 | // Save the numerator. |
| 3380 | __ movl(num, eax); |
| 3381 | |
| 3382 | // EAX = magic |
| 3383 | __ movl(eax, Immediate(magic)); |
| 3384 | |
| 3385 | // EDX:EAX = magic * numerator |
| 3386 | __ imull(num); |
| 3387 | |
| 3388 | if (imm > 0 && magic < 0) { |
| 3389 | // EDX += num |
| 3390 | __ addl(edx, num); |
| 3391 | } else if (imm < 0 && magic > 0) { |
| 3392 | __ subl(edx, num); |
| 3393 | } |
| 3394 | |
| 3395 | // Shift if needed. |
| 3396 | if (shift != 0) { |
| 3397 | __ sarl(edx, Immediate(shift)); |
| 3398 | } |
| 3399 | |
| 3400 | // EDX += 1 if EDX < 0 |
| 3401 | __ movl(eax, edx); |
| 3402 | __ shrl(edx, Immediate(31)); |
| 3403 | __ addl(edx, eax); |
| 3404 | |
| 3405 | if (instruction->IsRem()) { |
| 3406 | __ movl(eax, num); |
| 3407 | __ imull(edx, Immediate(imm)); |
| 3408 | __ subl(eax, edx); |
| 3409 | __ movl(edx, eax); |
| 3410 | } else { |
| 3411 | __ movl(eax, edx); |
| 3412 | } |
| 3413 | __ Bind(&end); |
| 3414 | } |
| 3415 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3416 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3417 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3418 | |
| 3419 | LocationSummary* locations = instruction->GetLocations(); |
| 3420 | Location out = locations->Out(); |
| 3421 | Location first = locations->InAt(0); |
| 3422 | Location second = locations->InAt(1); |
| 3423 | bool is_div = instruction->IsDiv(); |
| 3424 | |
| 3425 | switch (instruction->GetResultType()) { |
| 3426 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3427 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3428 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3429 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3430 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3431 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3432 | |
| 3433 | if (imm == 0) { |
| 3434 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3435 | } else if (imm == 1 || imm == -1) { |
| 3436 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3437 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3438 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3439 | } else { |
| 3440 | DCHECK(imm <= -2 || imm >= 2); |
| 3441 | GenerateDivRemWithAnyConstant(instruction); |
| 3442 | } |
| 3443 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3444 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3445 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3446 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3447 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3448 | Register second_reg = second.AsRegister<Register>(); |
| 3449 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3450 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3451 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3452 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3453 | __ cmpl(second_reg, Immediate(-1)); |
| 3454 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3455 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3456 | // edx:eax <- sign-extended of eax |
| 3457 | __ cdq(); |
| 3458 | // eax = quotient, edx = remainder |
| 3459 | __ idivl(second_reg); |
| 3460 | __ Bind(slow_path->GetExitLabel()); |
| 3461 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3462 | break; |
| 3463 | } |
| 3464 | |
| 3465 | case Primitive::kPrimLong: { |
| 3466 | InvokeRuntimeCallingConvention calling_convention; |
| 3467 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3468 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3469 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3470 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3471 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3472 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3473 | |
| 3474 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3475 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3476 | instruction, |
| 3477 | instruction->GetDexPc(), |
| 3478 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3479 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3480 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3481 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3482 | instruction, |
| 3483 | instruction->GetDexPc(), |
| 3484 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3485 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3486 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3487 | break; |
| 3488 | } |
| 3489 | |
| 3490 | default: |
| 3491 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3492 | } |
| 3493 | } |
| 3494 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3495 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3496 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3497 | ? LocationSummary::kCall |
| 3498 | : LocationSummary::kNoCall; |
| 3499 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3500 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3501 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3502 | case Primitive::kPrimInt: { |
| 3503 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3504 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3505 | locations->SetOut(Location::SameAsFirstInput()); |
| 3506 | // Intel uses edx:eax as the dividend. |
| 3507 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3508 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3509 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3510 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3511 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3512 | locations->AddTemp(Location::RequiresRegister()); |
| 3513 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3514 | break; |
| 3515 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3516 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3517 | InvokeRuntimeCallingConvention calling_convention; |
| 3518 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3519 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3520 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3521 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3522 | // Runtime helper puts the result in EAX, EDX. |
| 3523 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3524 | break; |
| 3525 | } |
| 3526 | case Primitive::kPrimFloat: |
| 3527 | case Primitive::kPrimDouble: { |
| 3528 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3529 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3530 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3531 | } else if (div->InputAt(1)->IsConstant()) { |
| 3532 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3533 | } else { |
| 3534 | locations->SetInAt(1, Location::Any()); |
| 3535 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3536 | locations->SetOut(Location::SameAsFirstInput()); |
| 3537 | break; |
| 3538 | } |
| 3539 | |
| 3540 | default: |
| 3541 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3542 | } |
| 3543 | } |
| 3544 | |
| 3545 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3546 | LocationSummary* locations = div->GetLocations(); |
| 3547 | Location first = locations->InAt(0); |
| 3548 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3549 | |
| 3550 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3551 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3552 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3553 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3554 | break; |
| 3555 | } |
| 3556 | |
| 3557 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3558 | if (second.IsFpuRegister()) { |
| 3559 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3560 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3561 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3562 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3563 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3564 | codegen_->LiteralFloatAddress( |
| 3565 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3566 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3567 | } else { |
| 3568 | DCHECK(second.IsStackSlot()); |
| 3569 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3570 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3571 | break; |
| 3572 | } |
| 3573 | |
| 3574 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3575 | if (second.IsFpuRegister()) { |
| 3576 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3577 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3578 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3579 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3580 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3581 | codegen_->LiteralDoubleAddress( |
| 3582 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3583 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3584 | } else { |
| 3585 | DCHECK(second.IsDoubleStackSlot()); |
| 3586 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3587 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3588 | break; |
| 3589 | } |
| 3590 | |
| 3591 | default: |
| 3592 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3593 | } |
| 3594 | } |
| 3595 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3596 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3597 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3598 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3599 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3600 | ? LocationSummary::kCall |
| 3601 | : LocationSummary::kNoCall; |
| 3602 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3603 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3604 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3605 | case Primitive::kPrimInt: { |
| 3606 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3607 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3608 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3609 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3610 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3611 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3612 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3613 | locations->AddTemp(Location::RequiresRegister()); |
| 3614 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3615 | break; |
| 3616 | } |
| 3617 | case Primitive::kPrimLong: { |
| 3618 | InvokeRuntimeCallingConvention calling_convention; |
| 3619 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3620 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3621 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3622 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3623 | // Runtime helper puts the result in EAX, EDX. |
| 3624 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3625 | break; |
| 3626 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3627 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3628 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3629 | locations->SetInAt(0, Location::Any()); |
| 3630 | locations->SetInAt(1, Location::Any()); |
| 3631 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3632 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3633 | break; |
| 3634 | } |
| 3635 | |
| 3636 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3637 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3638 | } |
| 3639 | } |
| 3640 | |
| 3641 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3642 | Primitive::Type type = rem->GetResultType(); |
| 3643 | switch (type) { |
| 3644 | case Primitive::kPrimInt: |
| 3645 | case Primitive::kPrimLong: { |
| 3646 | GenerateDivRemIntegral(rem); |
| 3647 | break; |
| 3648 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3649 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3650 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3651 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3652 | break; |
| 3653 | } |
| 3654 | default: |
| 3655 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3656 | } |
| 3657 | } |
| 3658 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3659 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3660 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3661 | ? LocationSummary::kCallOnSlowPath |
| 3662 | : LocationSummary::kNoCall; |
| 3663 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3664 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame^] | 3665 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3666 | case Primitive::kPrimByte: |
| 3667 | case Primitive::kPrimChar: |
| 3668 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3669 | case Primitive::kPrimInt: { |
| 3670 | locations->SetInAt(0, Location::Any()); |
| 3671 | break; |
| 3672 | } |
| 3673 | case Primitive::kPrimLong: { |
| 3674 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3675 | if (!instruction->IsConstant()) { |
| 3676 | locations->AddTemp(Location::RequiresRegister()); |
| 3677 | } |
| 3678 | break; |
| 3679 | } |
| 3680 | default: |
| 3681 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3682 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3683 | if (instruction->HasUses()) { |
| 3684 | locations->SetOut(Location::SameAsFirstInput()); |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3689 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3690 | codegen_->AddSlowPath(slow_path); |
| 3691 | |
| 3692 | LocationSummary* locations = instruction->GetLocations(); |
| 3693 | Location value = locations->InAt(0); |
| 3694 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3695 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame^] | 3696 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3697 | case Primitive::kPrimByte: |
| 3698 | case Primitive::kPrimChar: |
| 3699 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3700 | case Primitive::kPrimInt: { |
| 3701 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3702 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3703 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3704 | } else if (value.IsStackSlot()) { |
| 3705 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3706 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3707 | } else { |
| 3708 | DCHECK(value.IsConstant()) << value; |
| 3709 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3710 | __ jmp(slow_path->GetEntryLabel()); |
| 3711 | } |
| 3712 | } |
| 3713 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3714 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3715 | case Primitive::kPrimLong: { |
| 3716 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3717 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3718 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3719 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3720 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3721 | } else { |
| 3722 | DCHECK(value.IsConstant()) << value; |
| 3723 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3724 | __ jmp(slow_path->GetEntryLabel()); |
| 3725 | } |
| 3726 | } |
| 3727 | break; |
| 3728 | } |
| 3729 | default: |
| 3730 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3731 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3732 | } |
| 3733 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3734 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3735 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3736 | |
| 3737 | LocationSummary* locations = |
| 3738 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3739 | |
| 3740 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3741 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3742 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3743 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3744 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3745 | // The shift count needs to be in CL or a constant. |
| 3746 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3747 | locations->SetOut(Location::SameAsFirstInput()); |
| 3748 | break; |
| 3749 | } |
| 3750 | default: |
| 3751 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3752 | } |
| 3753 | } |
| 3754 | |
| 3755 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3756 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3757 | |
| 3758 | LocationSummary* locations = op->GetLocations(); |
| 3759 | Location first = locations->InAt(0); |
| 3760 | Location second = locations->InAt(1); |
| 3761 | DCHECK(first.Equals(locations->Out())); |
| 3762 | |
| 3763 | switch (op->GetResultType()) { |
| 3764 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3765 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3766 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3767 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3768 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3769 | DCHECK_EQ(ECX, second_reg); |
| 3770 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3771 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3772 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3773 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3774 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3775 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3776 | } |
| 3777 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3778 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3779 | if (shift == 0) { |
| 3780 | return; |
| 3781 | } |
| 3782 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3783 | if (op->IsShl()) { |
| 3784 | __ shll(first_reg, imm); |
| 3785 | } else if (op->IsShr()) { |
| 3786 | __ sarl(first_reg, imm); |
| 3787 | } else { |
| 3788 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3789 | } |
| 3790 | } |
| 3791 | break; |
| 3792 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3793 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3794 | if (second.IsRegister()) { |
| 3795 | Register second_reg = second.AsRegister<Register>(); |
| 3796 | DCHECK_EQ(ECX, second_reg); |
| 3797 | if (op->IsShl()) { |
| 3798 | GenerateShlLong(first, second_reg); |
| 3799 | } else if (op->IsShr()) { |
| 3800 | GenerateShrLong(first, second_reg); |
| 3801 | } else { |
| 3802 | GenerateUShrLong(first, second_reg); |
| 3803 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3804 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3805 | // Shift by a constant. |
| 3806 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3807 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3808 | if (shift != 0) { |
| 3809 | if (op->IsShl()) { |
| 3810 | GenerateShlLong(first, shift); |
| 3811 | } else if (op->IsShr()) { |
| 3812 | GenerateShrLong(first, shift); |
| 3813 | } else { |
| 3814 | GenerateUShrLong(first, shift); |
| 3815 | } |
| 3816 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3817 | } |
| 3818 | break; |
| 3819 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3820 | default: |
| 3821 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3822 | } |
| 3823 | } |
| 3824 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3825 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3826 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3827 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3828 | if (shift == 1) { |
| 3829 | // This is just an addition. |
| 3830 | __ addl(low, low); |
| 3831 | __ adcl(high, high); |
| 3832 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3833 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3834 | codegen_->EmitParallelMoves( |
| 3835 | loc.ToLow(), |
| 3836 | loc.ToHigh(), |
| 3837 | Primitive::kPrimInt, |
| 3838 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3839 | loc.ToLow(), |
| 3840 | Primitive::kPrimInt); |
| 3841 | } else if (shift > 32) { |
| 3842 | // Low part becomes 0. High part is low part << (shift-32). |
| 3843 | __ movl(high, low); |
| 3844 | __ shll(high, Immediate(shift - 32)); |
| 3845 | __ xorl(low, low); |
| 3846 | } else { |
| 3847 | // Between 1 and 31. |
| 3848 | __ shld(high, low, Immediate(shift)); |
| 3849 | __ shll(low, Immediate(shift)); |
| 3850 | } |
| 3851 | } |
| 3852 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3853 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3854 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3855 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3856 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3857 | __ testl(shifter, Immediate(32)); |
| 3858 | __ j(kEqual, &done); |
| 3859 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3860 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3861 | __ Bind(&done); |
| 3862 | } |
| 3863 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3864 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3865 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3866 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3867 | if (shift == 32) { |
| 3868 | // Need to copy the sign. |
| 3869 | DCHECK_NE(low, high); |
| 3870 | __ movl(low, high); |
| 3871 | __ sarl(high, Immediate(31)); |
| 3872 | } else if (shift > 32) { |
| 3873 | DCHECK_NE(low, high); |
| 3874 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3875 | __ movl(low, high); |
| 3876 | __ sarl(high, Immediate(31)); |
| 3877 | __ sarl(low, Immediate(shift - 32)); |
| 3878 | } else { |
| 3879 | // Between 1 and 31. |
| 3880 | __ shrd(low, high, Immediate(shift)); |
| 3881 | __ sarl(high, Immediate(shift)); |
| 3882 | } |
| 3883 | } |
| 3884 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3885 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3886 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3887 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3888 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3889 | __ testl(shifter, Immediate(32)); |
| 3890 | __ j(kEqual, &done); |
| 3891 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3892 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3893 | __ Bind(&done); |
| 3894 | } |
| 3895 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3896 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3897 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3898 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3899 | if (shift == 32) { |
| 3900 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3901 | codegen_->EmitParallelMoves( |
| 3902 | loc.ToHigh(), |
| 3903 | loc.ToLow(), |
| 3904 | Primitive::kPrimInt, |
| 3905 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3906 | loc.ToHigh(), |
| 3907 | Primitive::kPrimInt); |
| 3908 | } else if (shift > 32) { |
| 3909 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3910 | __ movl(low, high); |
| 3911 | __ shrl(low, Immediate(shift - 32)); |
| 3912 | __ xorl(high, high); |
| 3913 | } else { |
| 3914 | // Between 1 and 31. |
| 3915 | __ shrd(low, high, Immediate(shift)); |
| 3916 | __ shrl(high, Immediate(shift)); |
| 3917 | } |
| 3918 | } |
| 3919 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3920 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3921 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3922 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3923 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3924 | __ testl(shifter, Immediate(32)); |
| 3925 | __ j(kEqual, &done); |
| 3926 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3927 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3928 | __ Bind(&done); |
| 3929 | } |
| 3930 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3931 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3932 | LocationSummary* locations = |
| 3933 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3934 | |
| 3935 | switch (ror->GetResultType()) { |
| 3936 | case Primitive::kPrimLong: |
| 3937 | // Add the temporary needed. |
| 3938 | locations->AddTemp(Location::RequiresRegister()); |
| 3939 | FALLTHROUGH_INTENDED; |
| 3940 | case Primitive::kPrimInt: |
| 3941 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3942 | // The shift count needs to be in CL (unless it is a constant). |
| 3943 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3944 | locations->SetOut(Location::SameAsFirstInput()); |
| 3945 | break; |
| 3946 | default: |
| 3947 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3948 | UNREACHABLE(); |
| 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3953 | LocationSummary* locations = ror->GetLocations(); |
| 3954 | Location first = locations->InAt(0); |
| 3955 | Location second = locations->InAt(1); |
| 3956 | |
| 3957 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3958 | Register first_reg = first.AsRegister<Register>(); |
| 3959 | if (second.IsRegister()) { |
| 3960 | Register second_reg = second.AsRegister<Register>(); |
| 3961 | __ rorl(first_reg, second_reg); |
| 3962 | } else { |
| 3963 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3964 | __ rorl(first_reg, imm); |
| 3965 | } |
| 3966 | return; |
| 3967 | } |
| 3968 | |
| 3969 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3970 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3971 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3972 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3973 | if (second.IsRegister()) { |
| 3974 | Register second_reg = second.AsRegister<Register>(); |
| 3975 | DCHECK_EQ(second_reg, ECX); |
| 3976 | __ movl(temp_reg, first_reg_hi); |
| 3977 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3978 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3979 | __ movl(temp_reg, first_reg_hi); |
| 3980 | __ testl(second_reg, Immediate(32)); |
| 3981 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3982 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3983 | } else { |
| 3984 | int32_t shift_amt = |
| 3985 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3986 | if (shift_amt == 0) { |
| 3987 | // Already fine. |
| 3988 | return; |
| 3989 | } |
| 3990 | if (shift_amt == 32) { |
| 3991 | // Just swap. |
| 3992 | __ movl(temp_reg, first_reg_lo); |
| 3993 | __ movl(first_reg_lo, first_reg_hi); |
| 3994 | __ movl(first_reg_hi, temp_reg); |
| 3995 | return; |
| 3996 | } |
| 3997 | |
| 3998 | Immediate imm(shift_amt); |
| 3999 | // Save the constents of the low value. |
| 4000 | __ movl(temp_reg, first_reg_lo); |
| 4001 | |
| 4002 | // Shift right into low, feeding bits from high. |
| 4003 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 4004 | |
| 4005 | // Shift right into high, feeding bits from the original low. |
| 4006 | __ shrd(first_reg_hi, temp_reg, imm); |
| 4007 | |
| 4008 | // Swap if needed. |
| 4009 | if (shift_amt > 32) { |
| 4010 | __ movl(temp_reg, first_reg_lo); |
| 4011 | __ movl(first_reg_lo, first_reg_hi); |
| 4012 | __ movl(first_reg_hi, temp_reg); |
| 4013 | } |
| 4014 | } |
| 4015 | } |
| 4016 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4017 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 4018 | HandleShift(shl); |
| 4019 | } |
| 4020 | |
| 4021 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 4022 | HandleShift(shl); |
| 4023 | } |
| 4024 | |
| 4025 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 4026 | HandleShift(shr); |
| 4027 | } |
| 4028 | |
| 4029 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 4030 | HandleShift(shr); |
| 4031 | } |
| 4032 | |
| 4033 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 4034 | HandleShift(ushr); |
| 4035 | } |
| 4036 | |
| 4037 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 4038 | HandleShift(ushr); |
| 4039 | } |
| 4040 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4041 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4042 | LocationSummary* locations = |
| 4043 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4044 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4045 | if (instruction->IsStringAlloc()) { |
| 4046 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4047 | } else { |
| 4048 | InvokeRuntimeCallingConvention calling_convention; |
| 4049 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 4050 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 4051 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4055 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4056 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4057 | if (instruction->IsStringAlloc()) { |
| 4058 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 4059 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 4060 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 4061 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 4062 | __ call(Address(temp, code_offset.Int32Value())); |
| 4063 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4064 | } else { |
| 4065 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4066 | instruction, |
| 4067 | instruction->GetDexPc(), |
| 4068 | nullptr); |
| 4069 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 4070 | DCHECK(!codegen_->IsLeafMethod()); |
| 4071 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4072 | } |
| 4073 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4074 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4075 | LocationSummary* locations = |
| 4076 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4077 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4078 | InvokeRuntimeCallingConvention calling_convention; |
| 4079 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4080 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4081 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4085 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4086 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4087 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4088 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4089 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4090 | instruction, |
| 4091 | instruction->GetDexPc(), |
| 4092 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4093 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4094 | DCHECK(!codegen_->IsLeafMethod()); |
| 4095 | } |
| 4096 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4097 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4098 | LocationSummary* locations = |
| 4099 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4100 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4101 | if (location.IsStackSlot()) { |
| 4102 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4103 | } else if (location.IsDoubleStackSlot()) { |
| 4104 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4105 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4106 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4107 | } |
| 4108 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4109 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4110 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4111 | } |
| 4112 | |
| 4113 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4114 | LocationSummary* locations = |
| 4115 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4116 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4117 | } |
| 4118 | |
| 4119 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4120 | } |
| 4121 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4122 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4123 | LocationSummary* locations = |
| 4124 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4125 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4126 | locations->SetOut(Location::RequiresRegister()); |
| 4127 | } |
| 4128 | |
| 4129 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4130 | LocationSummary* locations = instruction->GetLocations(); |
| 4131 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4132 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4133 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4134 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4135 | } else { |
| 4136 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4137 | instruction->GetIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
| 4138 | } |
| 4139 | __ movl(locations->Out().AsRegister<Register>(), |
| 4140 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4141 | } |
| 4142 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4143 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4144 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4145 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4146 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4147 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4148 | } |
| 4149 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4150 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4151 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4152 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4153 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4154 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4155 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4156 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4157 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4158 | break; |
| 4159 | |
| 4160 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4161 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4162 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4163 | break; |
| 4164 | |
| 4165 | default: |
| 4166 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4167 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4168 | } |
| 4169 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4170 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4171 | LocationSummary* locations = |
| 4172 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4174 | locations->SetOut(Location::SameAsFirstInput()); |
| 4175 | } |
| 4176 | |
| 4177 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4178 | LocationSummary* locations = bool_not->GetLocations(); |
| 4179 | Location in = locations->InAt(0); |
| 4180 | Location out = locations->Out(); |
| 4181 | DCHECK(in.Equals(out)); |
| 4182 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4183 | } |
| 4184 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4185 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4186 | LocationSummary* locations = |
| 4187 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4188 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4189 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4190 | case Primitive::kPrimLong: { |
| 4191 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4192 | locations->SetInAt(1, Location::Any()); |
| 4193 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4194 | break; |
| 4195 | } |
| 4196 | case Primitive::kPrimFloat: |
| 4197 | case Primitive::kPrimDouble: { |
| 4198 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4199 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4200 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4201 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4202 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4203 | } else { |
| 4204 | locations->SetInAt(1, Location::Any()); |
| 4205 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4206 | locations->SetOut(Location::RequiresRegister()); |
| 4207 | break; |
| 4208 | } |
| 4209 | default: |
| 4210 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4211 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4215 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4216 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4217 | Location left = locations->InAt(0); |
| 4218 | Location right = locations->InAt(1); |
| 4219 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4220 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4221 | Condition less_cond = kLess; |
| 4222 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4223 | switch (compare->InputAt(0)->GetType()) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4224 | case Primitive::kPrimInt: { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 4225 | GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4226 | break; |
| 4227 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4228 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4229 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4230 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4231 | int32_t val_low = 0; |
| 4232 | int32_t val_high = 0; |
| 4233 | bool right_is_const = false; |
| 4234 | |
| 4235 | if (right.IsConstant()) { |
| 4236 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4237 | right_is_const = true; |
| 4238 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4239 | val_low = Low32Bits(val); |
| 4240 | val_high = High32Bits(val); |
| 4241 | } |
| 4242 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4243 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4244 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4245 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4246 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4247 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4248 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4249 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4250 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4251 | __ j(kLess, &less); // Signed compare. |
| 4252 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4253 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4254 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4255 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4256 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4257 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4258 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4259 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4260 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4261 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4262 | break; |
| 4263 | } |
| 4264 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4265 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4266 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4267 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4268 | break; |
| 4269 | } |
| 4270 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4271 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4272 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4273 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4274 | break; |
| 4275 | } |
| 4276 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4277 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4278 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4279 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4280 | __ movl(out, Immediate(0)); |
| 4281 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4282 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4283 | |
| 4284 | __ Bind(&greater); |
| 4285 | __ movl(out, Immediate(1)); |
| 4286 | __ jmp(&done); |
| 4287 | |
| 4288 | __ Bind(&less); |
| 4289 | __ movl(out, Immediate(-1)); |
| 4290 | |
| 4291 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4292 | } |
| 4293 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4294 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4295 | LocationSummary* locations = |
| 4296 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4297 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4298 | locations->SetInAt(i, Location::Any()); |
| 4299 | } |
| 4300 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4301 | } |
| 4302 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4303 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4304 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4305 | } |
| 4306 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4307 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4308 | /* |
| 4309 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4310 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4311 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4312 | */ |
| 4313 | switch (kind) { |
| 4314 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4315 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4316 | break; |
| 4317 | } |
| 4318 | case MemBarrierKind::kAnyStore: |
| 4319 | case MemBarrierKind::kLoadAny: |
| 4320 | case MemBarrierKind::kStoreStore: { |
| 4321 | // nop |
| 4322 | break; |
| 4323 | } |
| 4324 | default: |
| 4325 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4326 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4327 | } |
| 4328 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4329 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4330 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4331 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4332 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4333 | |
| 4334 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4335 | // is incompatible with it. |
| 4336 | if (GetGraph()->HasIrreducibleLoops() && |
| 4337 | (dispatch_info.method_load_kind == |
| 4338 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4339 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4340 | } |
| 4341 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4342 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4343 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4344 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4345 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4346 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4347 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4348 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4349 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4350 | 0u |
| 4351 | }; |
| 4352 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4353 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4354 | } |
| 4355 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4356 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4357 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4358 | Register temp) { |
| 4359 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4360 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4361 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4362 | return location.AsRegister<Register>(); |
| 4363 | } |
| 4364 | // For intrinsics we allow any location, so it may be on the stack. |
| 4365 | if (!location.IsRegister()) { |
| 4366 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4367 | return temp; |
| 4368 | } |
| 4369 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4370 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4371 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4372 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4373 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4374 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4375 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4376 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4377 | __ movl(temp, Address(ESP, stack_offset)); |
| 4378 | return temp; |
| 4379 | } |
| 4380 | return location.AsRegister<Register>(); |
| 4381 | } |
| 4382 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4383 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4384 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4385 | switch (invoke->GetMethodLoadKind()) { |
| 4386 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4387 | // temp = thread->string_init_entrypoint |
| 4388 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4389 | break; |
| 4390 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4391 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4392 | break; |
| 4393 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4394 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4395 | break; |
| 4396 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4397 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4398 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4399 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4400 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4401 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4402 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4403 | temp.AsRegister<Register>()); |
| 4404 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4405 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4406 | // Add the patch entry and bind its label at the end of the instruction. |
| 4407 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4408 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4409 | break; |
| 4410 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4411 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4412 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4413 | Register method_reg; |
| 4414 | Register reg = temp.AsRegister<Register>(); |
| 4415 | if (current_method.IsRegister()) { |
| 4416 | method_reg = current_method.AsRegister<Register>(); |
| 4417 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4418 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4419 | DCHECK(!current_method.IsValid()); |
| 4420 | method_reg = reg; |
| 4421 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4422 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4423 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4424 | __ movl(reg, Address(method_reg, |
| 4425 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4426 | // temp = temp[index_in_cache] |
| 4427 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4428 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4429 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4430 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4431 | } |
| 4432 | |
| 4433 | switch (invoke->GetCodePtrLocation()) { |
| 4434 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4435 | __ call(GetFrameEntryLabel()); |
| 4436 | break; |
| 4437 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4438 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4439 | Label* label = &relative_call_patches_.back().label; |
| 4440 | __ call(label); // Bind to the patch label, override at link time. |
| 4441 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4442 | break; |
| 4443 | } |
| 4444 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4445 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4446 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4447 | LOG(FATAL) << "Unsupported"; |
| 4448 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4449 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4450 | // (callee_method + offset_of_quick_compiled_code)() |
| 4451 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4452 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4453 | kX86WordSize).Int32Value())); |
| 4454 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4455 | } |
| 4456 | |
| 4457 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4458 | } |
| 4459 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4460 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4461 | Register temp = temp_in.AsRegister<Register>(); |
| 4462 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4463 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4464 | |
| 4465 | // Use the calling convention instead of the location of the receiver, as |
| 4466 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4467 | // slow path, the arguments have been moved to the right place, so here we are |
| 4468 | // guaranteed that the receiver is the first register of the calling convention. |
| 4469 | InvokeDexCallingConvention calling_convention; |
| 4470 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4471 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4472 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4473 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4474 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4475 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4476 | // emit a read barrier for the previous class reference load. |
| 4477 | // However this is not required in practice, as this is an |
| 4478 | // intermediate/temporary reference and because the current |
| 4479 | // concurrent copying collector keeps the from-space memory |
| 4480 | // intact/accessible until the end of the marking phase (the |
| 4481 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4482 | __ MaybeUnpoisonHeapReference(temp); |
| 4483 | // temp = temp->GetMethodAt(method_offset); |
| 4484 | __ movl(temp, Address(temp, method_offset)); |
| 4485 | // call temp->GetEntryPoint(); |
| 4486 | __ call(Address( |
| 4487 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4488 | } |
| 4489 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4490 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4491 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4492 | size_t size = |
| 4493 | method_patches_.size() + |
| 4494 | relative_call_patches_.size() + |
| 4495 | pc_relative_dex_cache_patches_.size(); |
| 4496 | linker_patches->reserve(size); |
| 4497 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4498 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4499 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4500 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4501 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4502 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4503 | info.target_method.dex_file, |
| 4504 | info.target_method.dex_method_index)); |
| 4505 | } |
| 4506 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4507 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4508 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4509 | info.target_method.dex_file, |
| 4510 | info.target_method.dex_method_index)); |
| 4511 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4512 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4513 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4514 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4515 | &info.target_dex_file, |
| 4516 | GetMethodAddressOffset(), |
| 4517 | info.element_offset)); |
| 4518 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4519 | } |
| 4520 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4521 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4522 | Register card, |
| 4523 | Register object, |
| 4524 | Register value, |
| 4525 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4526 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4527 | if (value_can_be_null) { |
| 4528 | __ testl(value, value); |
| 4529 | __ j(kEqual, &is_null); |
| 4530 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4531 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4532 | __ movl(temp, object); |
| 4533 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4534 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4535 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4536 | if (value_can_be_null) { |
| 4537 | __ Bind(&is_null); |
| 4538 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4539 | } |
| 4540 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4541 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4542 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4543 | |
| 4544 | bool object_field_get_with_read_barrier = |
| 4545 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4546 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4547 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4548 | kEmitCompilerReadBarrier ? |
| 4549 | LocationSummary::kCallOnSlowPath : |
| 4550 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4551 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4552 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4553 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4554 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4555 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4556 | // The output overlaps in case of long: we don't want the low move |
| 4557 | // to overwrite the object's location. Likewise, in the case of |
| 4558 | // an object field get with read barriers enabled, we do not want |
| 4559 | // the move to overwrite the object's location, as we need it to emit |
| 4560 | // the read barrier. |
| 4561 | locations->SetOut( |
| 4562 | Location::RequiresRegister(), |
| 4563 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4564 | Location::kOutputOverlap : |
| 4565 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4566 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4567 | |
| 4568 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4569 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4570 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4571 | // load the temp into the XMM and then copy the XMM into the |
| 4572 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4573 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4574 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4575 | // We need a temporary register for the read barrier marking slow |
| 4576 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4577 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4578 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4579 | } |
| 4580 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4581 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4582 | const FieldInfo& field_info) { |
| 4583 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4584 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4585 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4586 | Location base_loc = locations->InAt(0); |
| 4587 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4588 | Location out = locations->Out(); |
| 4589 | bool is_volatile = field_info.IsVolatile(); |
| 4590 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4591 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4592 | |
| 4593 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4594 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4595 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4596 | break; |
| 4597 | } |
| 4598 | |
| 4599 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4600 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4601 | break; |
| 4602 | } |
| 4603 | |
| 4604 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4605 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4606 | break; |
| 4607 | } |
| 4608 | |
| 4609 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4610 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4611 | break; |
| 4612 | } |
| 4613 | |
| 4614 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4615 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4616 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4617 | |
| 4618 | case Primitive::kPrimNot: { |
| 4619 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4620 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4621 | Location temp_loc = locations->GetTemp(0); |
| 4622 | // Note that a potential implicit null check is handled in this |
| 4623 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4624 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4625 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4626 | if (is_volatile) { |
| 4627 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4628 | } |
| 4629 | } else { |
| 4630 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4631 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4632 | if (is_volatile) { |
| 4633 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4634 | } |
| 4635 | // If read barriers are enabled, emit read barriers other than |
| 4636 | // Baker's using a slow path (and also unpoison the loaded |
| 4637 | // reference, if heap poisoning is enabled). |
| 4638 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4639 | } |
| 4640 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4644 | if (is_volatile) { |
| 4645 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4646 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4647 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4648 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4649 | __ psrlq(temp, Immediate(32)); |
| 4650 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4651 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4652 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4653 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4654 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4655 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4656 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4657 | break; |
| 4658 | } |
| 4659 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4660 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4661 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4662 | break; |
| 4663 | } |
| 4664 | |
| 4665 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4666 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4667 | break; |
| 4668 | } |
| 4669 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4670 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4671 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4672 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4673 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4674 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4675 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4676 | // Potential implicit null checks, in the case of reference or |
| 4677 | // long fields, are handled in the previous switch statement. |
| 4678 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4679 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4680 | } |
| 4681 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4682 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4683 | if (field_type == Primitive::kPrimNot) { |
| 4684 | // Memory barriers, in the case of references, are also handled |
| 4685 | // in the previous switch statement. |
| 4686 | } else { |
| 4687 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4688 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4689 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4693 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4694 | |
| 4695 | LocationSummary* locations = |
| 4696 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4697 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4698 | bool is_volatile = field_info.IsVolatile(); |
| 4699 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4700 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4701 | || (field_type == Primitive::kPrimByte); |
| 4702 | |
| 4703 | // The register allocator does not support multiple |
| 4704 | // inputs that die at entry with one in a specific register. |
| 4705 | if (is_byte_type) { |
| 4706 | // Ensure the value is in a byte register. |
| 4707 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4708 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4709 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4710 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4711 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4712 | } else { |
| 4713 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4714 | } |
| 4715 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4716 | // 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] | 4717 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4718 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4719 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4720 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4721 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4722 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4723 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4724 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4725 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4726 | } else { |
| 4727 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4728 | |
| 4729 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4730 | // Temporary registers for the write barrier. |
| 4731 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4732 | // Ensure the card is in a byte register. |
| 4733 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4734 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4735 | } |
| 4736 | } |
| 4737 | |
| 4738 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4739 | const FieldInfo& field_info, |
| 4740 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4741 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4742 | |
| 4743 | LocationSummary* locations = instruction->GetLocations(); |
| 4744 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4745 | Location value = locations->InAt(1); |
| 4746 | bool is_volatile = field_info.IsVolatile(); |
| 4747 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4748 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4749 | bool needs_write_barrier = |
| 4750 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4751 | |
| 4752 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4753 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4754 | } |
| 4755 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4756 | bool maybe_record_implicit_null_check_done = false; |
| 4757 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4758 | switch (field_type) { |
| 4759 | case Primitive::kPrimBoolean: |
| 4760 | case Primitive::kPrimByte: { |
| 4761 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4762 | break; |
| 4763 | } |
| 4764 | |
| 4765 | case Primitive::kPrimShort: |
| 4766 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4767 | if (value.IsConstant()) { |
| 4768 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4769 | __ movw(Address(base, offset), Immediate(v)); |
| 4770 | } else { |
| 4771 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4772 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4773 | break; |
| 4774 | } |
| 4775 | |
| 4776 | case Primitive::kPrimInt: |
| 4777 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4778 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4779 | // Note that in the case where `value` is a null reference, |
| 4780 | // we do not enter this block, as the reference does not |
| 4781 | // need poisoning. |
| 4782 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4783 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4784 | __ movl(temp, value.AsRegister<Register>()); |
| 4785 | __ PoisonHeapReference(temp); |
| 4786 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4787 | } else if (value.IsConstant()) { |
| 4788 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4789 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4790 | } else { |
| 4791 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4792 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4793 | break; |
| 4794 | } |
| 4795 | |
| 4796 | case Primitive::kPrimLong: { |
| 4797 | if (is_volatile) { |
| 4798 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4799 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4800 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4801 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4802 | __ punpckldq(temp1, temp2); |
| 4803 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4804 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4805 | } else if (value.IsConstant()) { |
| 4806 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4807 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4808 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4809 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4810 | } else { |
| 4811 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4812 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4813 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4814 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4815 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4816 | break; |
| 4817 | } |
| 4818 | |
| 4819 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4820 | if (value.IsConstant()) { |
| 4821 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4822 | __ movl(Address(base, offset), Immediate(v)); |
| 4823 | } else { |
| 4824 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4825 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4826 | break; |
| 4827 | } |
| 4828 | |
| 4829 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4830 | if (value.IsConstant()) { |
| 4831 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4832 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4833 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4834 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4835 | maybe_record_implicit_null_check_done = true; |
| 4836 | } else { |
| 4837 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4838 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4839 | break; |
| 4840 | } |
| 4841 | |
| 4842 | case Primitive::kPrimVoid: |
| 4843 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4844 | UNREACHABLE(); |
| 4845 | } |
| 4846 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4847 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4848 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4849 | } |
| 4850 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4851 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4852 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4853 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4854 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4855 | } |
| 4856 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4857 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4858 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4859 | } |
| 4860 | } |
| 4861 | |
| 4862 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4863 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4864 | } |
| 4865 | |
| 4866 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4867 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4868 | } |
| 4869 | |
| 4870 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4871 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4872 | } |
| 4873 | |
| 4874 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4875 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4876 | } |
| 4877 | |
| 4878 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4879 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4880 | } |
| 4881 | |
| 4882 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4883 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4884 | } |
| 4885 | |
| 4886 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4887 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4888 | } |
| 4889 | |
| 4890 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4891 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4892 | } |
| 4893 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4894 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4895 | HUnresolvedInstanceFieldGet* instruction) { |
| 4896 | FieldAccessCallingConventionX86 calling_convention; |
| 4897 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4898 | instruction, instruction->GetFieldType(), calling_convention); |
| 4899 | } |
| 4900 | |
| 4901 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4902 | HUnresolvedInstanceFieldGet* instruction) { |
| 4903 | FieldAccessCallingConventionX86 calling_convention; |
| 4904 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4905 | instruction->GetFieldType(), |
| 4906 | instruction->GetFieldIndex(), |
| 4907 | instruction->GetDexPc(), |
| 4908 | calling_convention); |
| 4909 | } |
| 4910 | |
| 4911 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4912 | HUnresolvedInstanceFieldSet* instruction) { |
| 4913 | FieldAccessCallingConventionX86 calling_convention; |
| 4914 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4915 | instruction, instruction->GetFieldType(), calling_convention); |
| 4916 | } |
| 4917 | |
| 4918 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4919 | HUnresolvedInstanceFieldSet* instruction) { |
| 4920 | FieldAccessCallingConventionX86 calling_convention; |
| 4921 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4922 | instruction->GetFieldType(), |
| 4923 | instruction->GetFieldIndex(), |
| 4924 | instruction->GetDexPc(), |
| 4925 | calling_convention); |
| 4926 | } |
| 4927 | |
| 4928 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4929 | HUnresolvedStaticFieldGet* instruction) { |
| 4930 | FieldAccessCallingConventionX86 calling_convention; |
| 4931 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4932 | instruction, instruction->GetFieldType(), calling_convention); |
| 4933 | } |
| 4934 | |
| 4935 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4936 | HUnresolvedStaticFieldGet* instruction) { |
| 4937 | FieldAccessCallingConventionX86 calling_convention; |
| 4938 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4939 | instruction->GetFieldType(), |
| 4940 | instruction->GetFieldIndex(), |
| 4941 | instruction->GetDexPc(), |
| 4942 | calling_convention); |
| 4943 | } |
| 4944 | |
| 4945 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4946 | HUnresolvedStaticFieldSet* instruction) { |
| 4947 | FieldAccessCallingConventionX86 calling_convention; |
| 4948 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4949 | instruction, instruction->GetFieldType(), calling_convention); |
| 4950 | } |
| 4951 | |
| 4952 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4953 | HUnresolvedStaticFieldSet* instruction) { |
| 4954 | FieldAccessCallingConventionX86 calling_convention; |
| 4955 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4956 | instruction->GetFieldType(), |
| 4957 | instruction->GetFieldIndex(), |
| 4958 | instruction->GetDexPc(), |
| 4959 | calling_convention); |
| 4960 | } |
| 4961 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4962 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4963 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4964 | ? LocationSummary::kCallOnSlowPath |
| 4965 | : LocationSummary::kNoCall; |
| 4966 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4967 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4968 | ? Location::RequiresRegister() |
| 4969 | : Location::Any(); |
| 4970 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4971 | if (instruction->HasUses()) { |
| 4972 | locations->SetOut(Location::SameAsFirstInput()); |
| 4973 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4974 | } |
| 4975 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4976 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4977 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4978 | return; |
| 4979 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4980 | LocationSummary* locations = instruction->GetLocations(); |
| 4981 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4982 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4983 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4984 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4985 | } |
| 4986 | |
| 4987 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4988 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4989 | codegen_->AddSlowPath(slow_path); |
| 4990 | |
| 4991 | LocationSummary* locations = instruction->GetLocations(); |
| 4992 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4993 | |
| 4994 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4995 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4996 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4997 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4998 | } else { |
| 4999 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5000 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5001 | __ jmp(slow_path->GetEntryLabel()); |
| 5002 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5003 | } |
| 5004 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5005 | } |
| 5006 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5007 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5008 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5009 | GenerateImplicitNullCheck(instruction); |
| 5010 | } else { |
| 5011 | GenerateExplicitNullCheck(instruction); |
| 5012 | } |
| 5013 | } |
| 5014 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5015 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5016 | bool object_array_get_with_read_barrier = |
| 5017 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5018 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5019 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5020 | object_array_get_with_read_barrier ? |
| 5021 | LocationSummary::kCallOnSlowPath : |
| 5022 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5023 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5024 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5025 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5026 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5027 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5028 | // The output overlaps in case of long: we don't want the low move |
| 5029 | // to overwrite the array's location. Likewise, in the case of an |
| 5030 | // object array get with read barriers enabled, we do not want the |
| 5031 | // move to overwrite the array's location, as we need it to emit |
| 5032 | // the read barrier. |
| 5033 | locations->SetOut( |
| 5034 | Location::RequiresRegister(), |
| 5035 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5036 | Location::kOutputOverlap : |
| 5037 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5038 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5039 | // We need a temporary register for the read barrier marking slow |
| 5040 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 5041 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5042 | locations->AddTemp(Location::RequiresRegister()); |
| 5043 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5047 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5048 | Location obj_loc = locations->InAt(0); |
| 5049 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5050 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5051 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5052 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5053 | Primitive::Type type = instruction->GetType(); |
| 5054 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5055 | case Primitive::kPrimBoolean: { |
| 5056 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5057 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5058 | if (index.IsConstant()) { |
| 5059 | __ movzxb(out, Address(obj, |
| 5060 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5061 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5062 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5063 | } |
| 5064 | break; |
| 5065 | } |
| 5066 | |
| 5067 | case Primitive::kPrimByte: { |
| 5068 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5069 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5070 | if (index.IsConstant()) { |
| 5071 | __ movsxb(out, Address(obj, |
| 5072 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5073 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5074 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5075 | } |
| 5076 | break; |
| 5077 | } |
| 5078 | |
| 5079 | case Primitive::kPrimShort: { |
| 5080 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5081 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5082 | if (index.IsConstant()) { |
| 5083 | __ movsxw(out, Address(obj, |
| 5084 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5085 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5086 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5087 | } |
| 5088 | break; |
| 5089 | } |
| 5090 | |
| 5091 | case Primitive::kPrimChar: { |
| 5092 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5093 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5094 | if (index.IsConstant()) { |
| 5095 | __ movzxw(out, Address(obj, |
| 5096 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5097 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5098 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5099 | } |
| 5100 | break; |
| 5101 | } |
| 5102 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5103 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5104 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_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 | __ movl(out, Address(obj, |
| 5108 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5109 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5110 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5111 | } |
| 5112 | break; |
| 5113 | } |
| 5114 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5115 | case Primitive::kPrimNot: { |
| 5116 | static_assert( |
| 5117 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5118 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5119 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5120 | // /* HeapReference<Object> */ out = |
| 5121 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5122 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5123 | Location temp = locations->GetTemp(0); |
| 5124 | // Note that a potential implicit null check is handled in this |
| 5125 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5126 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5127 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5128 | } else { |
| 5129 | Register out = out_loc.AsRegister<Register>(); |
| 5130 | if (index.IsConstant()) { |
| 5131 | uint32_t offset = |
| 5132 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5133 | __ movl(out, Address(obj, offset)); |
| 5134 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5135 | // If read barriers are enabled, emit read barriers other than |
| 5136 | // Baker's using a slow path (and also unpoison the loaded |
| 5137 | // reference, if heap poisoning is enabled). |
| 5138 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5139 | } else { |
| 5140 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5141 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5142 | // If read barriers are enabled, emit read barriers other than |
| 5143 | // Baker's using a slow path (and also unpoison the loaded |
| 5144 | // reference, if heap poisoning is enabled). |
| 5145 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5146 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5147 | } |
| 5148 | } |
| 5149 | break; |
| 5150 | } |
| 5151 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5152 | case Primitive::kPrimLong: { |
| 5153 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5154 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5155 | if (index.IsConstant()) { |
| 5156 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5157 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5158 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5159 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5160 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5161 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5162 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5163 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5164 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5165 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5166 | } |
| 5167 | break; |
| 5168 | } |
| 5169 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5170 | case Primitive::kPrimFloat: { |
| 5171 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5172 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5173 | if (index.IsConstant()) { |
| 5174 | __ movss(out, Address(obj, |
| 5175 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5176 | } else { |
| 5177 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5178 | } |
| 5179 | break; |
| 5180 | } |
| 5181 | |
| 5182 | case Primitive::kPrimDouble: { |
| 5183 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5184 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5185 | if (index.IsConstant()) { |
| 5186 | __ movsd(out, Address(obj, |
| 5187 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5188 | } else { |
| 5189 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5190 | } |
| 5191 | break; |
| 5192 | } |
| 5193 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5194 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5195 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5196 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5197 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5198 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5199 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5200 | // Potential implicit null checks, in the case of reference or |
| 5201 | // long arrays, are handled in the previous switch statement. |
| 5202 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5203 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5204 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5205 | } |
| 5206 | |
| 5207 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5208 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5209 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5210 | bool needs_write_barrier = |
| 5211 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5212 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5213 | bool object_array_set_with_read_barrier = |
| 5214 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5215 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5216 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5217 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5218 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5219 | LocationSummary::kCallOnSlowPath : |
| 5220 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5221 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5222 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5223 | || (value_type == Primitive::kPrimByte); |
| 5224 | // We need the inputs to be different than the output in case of long operation. |
| 5225 | // In case of a byte operation, the register allocator does not support multiple |
| 5226 | // inputs that die at entry with one in a specific register. |
| 5227 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5228 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5229 | if (is_byte_type) { |
| 5230 | // Ensure the value is in a byte register. |
| 5231 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5232 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5233 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5234 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5235 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5236 | } |
| 5237 | if (needs_write_barrier) { |
| 5238 | // Temporary registers for the write barrier. |
| 5239 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5240 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5241 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5242 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5246 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5247 | Location array_loc = locations->InAt(0); |
| 5248 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5249 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5250 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5251 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5252 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5253 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5254 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5255 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5256 | bool needs_write_barrier = |
| 5257 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5258 | |
| 5259 | switch (value_type) { |
| 5260 | case Primitive::kPrimBoolean: |
| 5261 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5262 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5263 | Address address = index.IsConstant() |
| 5264 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5265 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5266 | if (value.IsRegister()) { |
| 5267 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5268 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5269 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5270 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5271 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5272 | break; |
| 5273 | } |
| 5274 | |
| 5275 | case Primitive::kPrimShort: |
| 5276 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5277 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5278 | Address address = index.IsConstant() |
| 5279 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5280 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5281 | if (value.IsRegister()) { |
| 5282 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5283 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5284 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5285 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5286 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5287 | break; |
| 5288 | } |
| 5289 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5290 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5291 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5292 | Address address = index.IsConstant() |
| 5293 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5294 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5295 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5296 | if (!value.IsRegister()) { |
| 5297 | // Just setting null. |
| 5298 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5299 | DCHECK(value.IsConstant()) << value; |
| 5300 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5301 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5302 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5303 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5304 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5305 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5306 | |
| 5307 | DCHECK(needs_write_barrier); |
| 5308 | Register register_value = value.AsRegister<Register>(); |
| 5309 | NearLabel done, not_null, do_put; |
| 5310 | SlowPathCode* slow_path = nullptr; |
| 5311 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5312 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5313 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5314 | codegen_->AddSlowPath(slow_path); |
| 5315 | if (instruction->GetValueCanBeNull()) { |
| 5316 | __ testl(register_value, register_value); |
| 5317 | __ j(kNotEqual, ¬_null); |
| 5318 | __ movl(address, Immediate(0)); |
| 5319 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5320 | __ jmp(&done); |
| 5321 | __ Bind(¬_null); |
| 5322 | } |
| 5323 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5324 | if (kEmitCompilerReadBarrier) { |
| 5325 | // When read barriers are enabled, the type checking |
| 5326 | // instrumentation requires two read barriers: |
| 5327 | // |
| 5328 | // __ movl(temp2, temp); |
| 5329 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5330 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5331 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5332 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5333 | // |
| 5334 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5335 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5336 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5337 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5338 | // |
| 5339 | // __ cmpl(temp, temp2); |
| 5340 | // |
| 5341 | // However, the second read barrier may trash `temp`, as it |
| 5342 | // is a temporary register, and as such would not be saved |
| 5343 | // along with live registers before calling the runtime (nor |
| 5344 | // restored afterwards). So in this case, we bail out and |
| 5345 | // delegate the work to the array set slow path. |
| 5346 | // |
| 5347 | // TODO: Extend the register allocator to support a new |
| 5348 | // "(locally) live temp" location so as to avoid always |
| 5349 | // going into the slow path when read barriers are enabled. |
| 5350 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5351 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5352 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5353 | __ movl(temp, Address(array, class_offset)); |
| 5354 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5355 | __ MaybeUnpoisonHeapReference(temp); |
| 5356 | |
| 5357 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5358 | __ movl(temp, Address(temp, component_offset)); |
| 5359 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5360 | // nor the object reference in `register_value->klass`, as |
| 5361 | // we are comparing two poisoned references. |
| 5362 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5363 | |
| 5364 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5365 | __ j(kEqual, &do_put); |
| 5366 | // If heap poisoning is enabled, the `temp` reference has |
| 5367 | // not been unpoisoned yet; unpoison it now. |
| 5368 | __ MaybeUnpoisonHeapReference(temp); |
| 5369 | |
| 5370 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5371 | __ movl(temp, Address(temp, super_offset)); |
| 5372 | // If heap poisoning is enabled, no need to unpoison |
| 5373 | // `temp`, as we are comparing against null below. |
| 5374 | __ testl(temp, temp); |
| 5375 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5376 | __ Bind(&do_put); |
| 5377 | } else { |
| 5378 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5379 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5380 | } |
| 5381 | } |
| 5382 | |
| 5383 | if (kPoisonHeapReferences) { |
| 5384 | __ movl(temp, register_value); |
| 5385 | __ PoisonHeapReference(temp); |
| 5386 | __ movl(address, temp); |
| 5387 | } else { |
| 5388 | __ movl(address, register_value); |
| 5389 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5390 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5391 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5392 | } |
| 5393 | |
| 5394 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5395 | codegen_->MarkGCCard( |
| 5396 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5397 | __ Bind(&done); |
| 5398 | |
| 5399 | if (slow_path != nullptr) { |
| 5400 | __ Bind(slow_path->GetExitLabel()); |
| 5401 | } |
| 5402 | |
| 5403 | break; |
| 5404 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5405 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5406 | case Primitive::kPrimInt: { |
| 5407 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5408 | Address address = index.IsConstant() |
| 5409 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5410 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5411 | if (value.IsRegister()) { |
| 5412 | __ movl(address, value.AsRegister<Register>()); |
| 5413 | } else { |
| 5414 | DCHECK(value.IsConstant()) << value; |
| 5415 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5416 | __ movl(address, Immediate(v)); |
| 5417 | } |
| 5418 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5419 | break; |
| 5420 | } |
| 5421 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5422 | case Primitive::kPrimLong: { |
| 5423 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5424 | if (index.IsConstant()) { |
| 5425 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5426 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5427 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5428 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5429 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5430 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5431 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5432 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5433 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5434 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5435 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5436 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5437 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5438 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5439 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5440 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5441 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5442 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5443 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5444 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5445 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5446 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5447 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5448 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5449 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5450 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5451 | Immediate(High32Bits(val))); |
| 5452 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5453 | } |
| 5454 | break; |
| 5455 | } |
| 5456 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5457 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5458 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5459 | Address address = index.IsConstant() |
| 5460 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5461 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5462 | if (value.IsFpuRegister()) { |
| 5463 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5464 | } else { |
| 5465 | DCHECK(value.IsConstant()); |
| 5466 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5467 | __ movl(address, Immediate(v)); |
| 5468 | } |
| 5469 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5470 | break; |
| 5471 | } |
| 5472 | |
| 5473 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5474 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5475 | Address address = index.IsConstant() |
| 5476 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5477 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5478 | if (value.IsFpuRegister()) { |
| 5479 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5480 | } else { |
| 5481 | DCHECK(value.IsConstant()); |
| 5482 | Address address_hi = index.IsConstant() ? |
| 5483 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5484 | offset + kX86WordSize) : |
| 5485 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5486 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5487 | __ movl(address, Immediate(Low32Bits(v))); |
| 5488 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5489 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5490 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5491 | break; |
| 5492 | } |
| 5493 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5494 | case Primitive::kPrimVoid: |
| 5495 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5496 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5497 | } |
| 5498 | } |
| 5499 | |
| 5500 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5501 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5502 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5503 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5504 | } |
| 5505 | |
| 5506 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5507 | LocationSummary* locations = instruction->GetLocations(); |
| 5508 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5509 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5510 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5511 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5512 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5516 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5517 | ? LocationSummary::kCallOnSlowPath |
| 5518 | : LocationSummary::kNoCall; |
| 5519 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5520 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5521 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5522 | if (instruction->HasUses()) { |
| 5523 | locations->SetOut(Location::SameAsFirstInput()); |
| 5524 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5528 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5529 | Location index_loc = locations->InAt(0); |
| 5530 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5531 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5532 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5533 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5534 | if (length_loc.IsConstant()) { |
| 5535 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5536 | if (index_loc.IsConstant()) { |
| 5537 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5538 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5539 | if (index < 0 || index >= length) { |
| 5540 | codegen_->AddSlowPath(slow_path); |
| 5541 | __ jmp(slow_path->GetEntryLabel()); |
| 5542 | } else { |
| 5543 | // Some optimization after BCE may have generated this, and we should not |
| 5544 | // generate a bounds check if it is a valid range. |
| 5545 | } |
| 5546 | return; |
| 5547 | } |
| 5548 | |
| 5549 | // We have to reverse the jump condition because the length is the constant. |
| 5550 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5551 | __ cmpl(index_reg, Immediate(length)); |
| 5552 | codegen_->AddSlowPath(slow_path); |
| 5553 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5554 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5555 | Register length = length_loc.AsRegister<Register>(); |
| 5556 | if (index_loc.IsConstant()) { |
| 5557 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5558 | __ cmpl(length, Immediate(value)); |
| 5559 | } else { |
| 5560 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5561 | } |
| 5562 | codegen_->AddSlowPath(slow_path); |
| 5563 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5564 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5565 | } |
| 5566 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5567 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5568 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5572 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5573 | } |
| 5574 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5575 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5576 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5577 | } |
| 5578 | |
| 5579 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5580 | HBasicBlock* block = instruction->GetBlock(); |
| 5581 | if (block->GetLoopInformation() != nullptr) { |
| 5582 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5583 | // The back edge will generate the suspend check. |
| 5584 | return; |
| 5585 | } |
| 5586 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5587 | // The goto will generate the suspend check. |
| 5588 | return; |
| 5589 | } |
| 5590 | GenerateSuspendCheck(instruction, nullptr); |
| 5591 | } |
| 5592 | |
| 5593 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5594 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5595 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5596 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5597 | if (slow_path == nullptr) { |
| 5598 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5599 | instruction->SetSlowPath(slow_path); |
| 5600 | codegen_->AddSlowPath(slow_path); |
| 5601 | if (successor != nullptr) { |
| 5602 | DCHECK(successor->IsLoopHeader()); |
| 5603 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5604 | } |
| 5605 | } else { |
| 5606 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5607 | } |
| 5608 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5609 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5610 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5611 | if (successor == nullptr) { |
| 5612 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5613 | __ Bind(slow_path->GetReturnLabel()); |
| 5614 | } else { |
| 5615 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5616 | __ jmp(slow_path->GetEntryLabel()); |
| 5617 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5618 | } |
| 5619 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5620 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5621 | return codegen_->GetAssembler(); |
| 5622 | } |
| 5623 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5624 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5625 | ScratchRegisterScope ensure_scratch( |
| 5626 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5627 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5628 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5629 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5630 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5631 | } |
| 5632 | |
| 5633 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5634 | ScratchRegisterScope ensure_scratch( |
| 5635 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5636 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5637 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5638 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5639 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5640 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5641 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5645 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5646 | Location source = move->GetSource(); |
| 5647 | Location destination = move->GetDestination(); |
| 5648 | |
| 5649 | if (source.IsRegister()) { |
| 5650 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5651 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5652 | } else if (destination.IsFpuRegister()) { |
| 5653 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5654 | } else { |
| 5655 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5656 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5657 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5658 | } else if (source.IsRegisterPair()) { |
| 5659 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5660 | // Create stack space for 2 elements. |
| 5661 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5662 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5663 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5664 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5665 | // And remove the temporary stack space we allocated. |
| 5666 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5667 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5668 | if (destination.IsRegister()) { |
| 5669 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5670 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5671 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5672 | } else if (destination.IsRegisterPair()) { |
| 5673 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5674 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5675 | __ psrlq(src_reg, Immediate(32)); |
| 5676 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5677 | } else if (destination.IsStackSlot()) { |
| 5678 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5679 | } else { |
| 5680 | DCHECK(destination.IsDoubleStackSlot()); |
| 5681 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5682 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5683 | } else if (source.IsStackSlot()) { |
| 5684 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5685 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5686 | } else if (destination.IsFpuRegister()) { |
| 5687 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5688 | } else { |
| 5689 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5690 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5691 | } |
| 5692 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5693 | if (destination.IsRegisterPair()) { |
| 5694 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5695 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5696 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5697 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5698 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5699 | } else { |
| 5700 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5701 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5702 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5703 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5704 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5705 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5706 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5707 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5708 | if (value == 0) { |
| 5709 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5710 | } else { |
| 5711 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5712 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5713 | } else { |
| 5714 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5715 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5716 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5717 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5718 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5719 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5720 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5721 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5722 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5723 | if (value == 0) { |
| 5724 | // Easy handling of 0.0. |
| 5725 | __ xorps(dest, dest); |
| 5726 | } else { |
| 5727 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5728 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5729 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5730 | __ movl(temp, Immediate(value)); |
| 5731 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5732 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5733 | } else { |
| 5734 | DCHECK(destination.IsStackSlot()) << destination; |
| 5735 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5736 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5737 | } else if (constant->IsLongConstant()) { |
| 5738 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5739 | int32_t low_value = Low32Bits(value); |
| 5740 | int32_t high_value = High32Bits(value); |
| 5741 | Immediate low(low_value); |
| 5742 | Immediate high(high_value); |
| 5743 | if (destination.IsDoubleStackSlot()) { |
| 5744 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5745 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5746 | } else { |
| 5747 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5748 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5749 | } |
| 5750 | } else { |
| 5751 | DCHECK(constant->IsDoubleConstant()); |
| 5752 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5753 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5754 | int32_t low_value = Low32Bits(value); |
| 5755 | int32_t high_value = High32Bits(value); |
| 5756 | Immediate low(low_value); |
| 5757 | Immediate high(high_value); |
| 5758 | if (destination.IsFpuRegister()) { |
| 5759 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5760 | if (value == 0) { |
| 5761 | // Easy handling of 0.0. |
| 5762 | __ xorpd(dest, dest); |
| 5763 | } else { |
| 5764 | __ pushl(high); |
| 5765 | __ pushl(low); |
| 5766 | __ movsd(dest, Address(ESP, 0)); |
| 5767 | __ addl(ESP, Immediate(8)); |
| 5768 | } |
| 5769 | } else { |
| 5770 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5771 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5772 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5773 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5774 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5775 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5776 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5777 | } |
| 5778 | } |
| 5779 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5780 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5781 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5782 | ScratchRegisterScope ensure_scratch( |
| 5783 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5784 | |
| 5785 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5786 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5787 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5788 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5789 | } |
| 5790 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5791 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5792 | ScratchRegisterScope ensure_scratch( |
| 5793 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5794 | |
| 5795 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5796 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5797 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5798 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5799 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5800 | } |
| 5801 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5802 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5803 | ScratchRegisterScope ensure_scratch1( |
| 5804 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5805 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5806 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5807 | ScratchRegisterScope ensure_scratch2( |
| 5808 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5809 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5810 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5811 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5812 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5813 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5814 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5815 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5819 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5820 | Location source = move->GetSource(); |
| 5821 | Location destination = move->GetDestination(); |
| 5822 | |
| 5823 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5824 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5825 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5826 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5827 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5828 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5829 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5830 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5831 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5832 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5833 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5834 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5835 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5836 | // Use XOR Swap algorithm to avoid a temporary. |
| 5837 | DCHECK_NE(source.reg(), destination.reg()); |
| 5838 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5839 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5840 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5841 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5842 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5843 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5844 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5845 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5846 | // Take advantage of the 16 bytes in the XMM register. |
| 5847 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5848 | Address stack(ESP, destination.GetStackIndex()); |
| 5849 | // Load the double into the high doubleword. |
| 5850 | __ movhpd(reg, stack); |
| 5851 | |
| 5852 | // Store the low double into the destination. |
| 5853 | __ movsd(stack, reg); |
| 5854 | |
| 5855 | // Move the high double to the low double. |
| 5856 | __ psrldq(reg, Immediate(8)); |
| 5857 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5858 | // Take advantage of the 16 bytes in the XMM register. |
| 5859 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5860 | Address stack(ESP, source.GetStackIndex()); |
| 5861 | // Load the double into the high doubleword. |
| 5862 | __ movhpd(reg, stack); |
| 5863 | |
| 5864 | // Store the low double into the destination. |
| 5865 | __ movsd(stack, reg); |
| 5866 | |
| 5867 | // Move the high double to the low double. |
| 5868 | __ psrldq(reg, Immediate(8)); |
| 5869 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5870 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5871 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5872 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5873 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5874 | } |
| 5875 | } |
| 5876 | |
| 5877 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5878 | __ pushl(static_cast<Register>(reg)); |
| 5879 | } |
| 5880 | |
| 5881 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5882 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5883 | } |
| 5884 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5885 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5886 | InvokeRuntimeCallingConvention calling_convention; |
| 5887 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5888 | cls, |
| 5889 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5890 | Location::RegisterLocation(EAX), |
| 5891 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5895 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5896 | if (cls->NeedsAccessCheck()) { |
| 5897 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5898 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5899 | cls, |
| 5900 | cls->GetDexPc(), |
| 5901 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5902 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5903 | return; |
| 5904 | } |
| 5905 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5906 | Location out_loc = locations->Out(); |
| 5907 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5908 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5909 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5910 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5911 | DCHECK(!cls->CanCallRuntime()); |
| 5912 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5913 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5914 | GenerateGcRootFieldLoad( |
| 5915 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5916 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5917 | // /* GcRoot<mirror::Class>[] */ out = |
| 5918 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5919 | __ movl(out, Address(current_method, |
| 5920 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5921 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5922 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5923 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5924 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5925 | DCHECK(cls->CanCallRuntime()); |
| 5926 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5927 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5928 | codegen_->AddSlowPath(slow_path); |
| 5929 | |
| 5930 | if (!cls->IsInDexCache()) { |
| 5931 | __ testl(out, out); |
| 5932 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5933 | } |
| 5934 | |
| 5935 | if (cls->MustGenerateClinitCheck()) { |
| 5936 | GenerateClassInitializationCheck(slow_path, out); |
| 5937 | } else { |
| 5938 | __ Bind(slow_path->GetExitLabel()); |
| 5939 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5940 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5941 | } |
| 5942 | } |
| 5943 | |
| 5944 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5945 | LocationSummary* locations = |
| 5946 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5947 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5948 | if (check->HasUses()) { |
| 5949 | locations->SetOut(Location::SameAsFirstInput()); |
| 5950 | } |
| 5951 | } |
| 5952 | |
| 5953 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5954 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5955 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5956 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5957 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5958 | GenerateClassInitializationCheck(slow_path, |
| 5959 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5960 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5961 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5962 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5963 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5964 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5965 | Immediate(mirror::Class::kStatusInitialized)); |
| 5966 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5967 | __ Bind(slow_path->GetExitLabel()); |
| 5968 | // No need for memory fence, thanks to the X86 memory model. |
| 5969 | } |
| 5970 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5971 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5972 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5973 | ? LocationSummary::kCallOnSlowPath |
| 5974 | : LocationSummary::kNoCall; |
| 5975 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5976 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5977 | locations->SetOut(Location::RequiresRegister()); |
| 5978 | } |
| 5979 | |
| 5980 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5981 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5982 | Location out_loc = locations->Out(); |
| 5983 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5984 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5985 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5986 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5987 | GenerateGcRootFieldLoad( |
| 5988 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5989 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5990 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5991 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5992 | GenerateGcRootFieldLoad( |
| 5993 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5994 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5995 | if (!load->IsInDexCache()) { |
| 5996 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5997 | codegen_->AddSlowPath(slow_path); |
| 5998 | __ testl(out, out); |
| 5999 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6000 | __ Bind(slow_path->GetExitLabel()); |
| 6001 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6002 | } |
| 6003 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6004 | static Address GetExceptionTlsAddress() { |
| 6005 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 6006 | } |
| 6007 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6008 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6009 | LocationSummary* locations = |
| 6010 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6011 | locations->SetOut(Location::RequiresRegister()); |
| 6012 | } |
| 6013 | |
| 6014 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6015 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6016 | } |
| 6017 | |
| 6018 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6019 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6020 | } |
| 6021 | |
| 6022 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6023 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6024 | } |
| 6025 | |
| 6026 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6027 | LocationSummary* locations = |
| 6028 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6029 | InvokeRuntimeCallingConvention calling_convention; |
| 6030 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6031 | } |
| 6032 | |
| 6033 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6034 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 6035 | instruction, |
| 6036 | instruction->GetDexPc(), |
| 6037 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6038 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6039 | } |
| 6040 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6041 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6042 | return kEmitCompilerReadBarrier && |
| 6043 | (kUseBakerReadBarrier || |
| 6044 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6045 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6046 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6047 | } |
| 6048 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6049 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6050 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6051 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6052 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6053 | case TypeCheckKind::kExactCheck: |
| 6054 | case TypeCheckKind::kAbstractClassCheck: |
| 6055 | case TypeCheckKind::kClassHierarchyCheck: |
| 6056 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6057 | call_kind = |
| 6058 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6059 | break; |
| 6060 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6061 | case TypeCheckKind::kUnresolvedCheck: |
| 6062 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6063 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6064 | break; |
| 6065 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6066 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6067 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6068 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6069 | locations->SetInAt(1, Location::Any()); |
| 6070 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6071 | locations->SetOut(Location::RequiresRegister()); |
| 6072 | // When read barriers are enabled, we need a temporary register for |
| 6073 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6074 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6075 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6076 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6077 | } |
| 6078 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6079 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6080 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6081 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6082 | Location obj_loc = locations->InAt(0); |
| 6083 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6084 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6085 | Location out_loc = locations->Out(); |
| 6086 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6087 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6088 | locations->GetTemp(0) : |
| 6089 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6090 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6091 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6092 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6093 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6094 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6095 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6096 | |
| 6097 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6098 | // Avoid null check if we know obj is not null. |
| 6099 | if (instruction->MustDoNullCheck()) { |
| 6100 | __ testl(obj, obj); |
| 6101 | __ j(kEqual, &zero); |
| 6102 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6103 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6104 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6105 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6106 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6107 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6108 | case TypeCheckKind::kExactCheck: { |
| 6109 | if (cls.IsRegister()) { |
| 6110 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6111 | } else { |
| 6112 | DCHECK(cls.IsStackSlot()) << cls; |
| 6113 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6114 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6115 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6116 | // Classes must be equal for the instanceof to succeed. |
| 6117 | __ j(kNotEqual, &zero); |
| 6118 | __ movl(out, Immediate(1)); |
| 6119 | __ jmp(&done); |
| 6120 | break; |
| 6121 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6122 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6123 | case TypeCheckKind::kAbstractClassCheck: { |
| 6124 | // If the class is abstract, we eagerly fetch the super class of the |
| 6125 | // object to avoid doing a comparison we know will fail. |
| 6126 | NearLabel loop; |
| 6127 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6128 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6129 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6130 | __ testl(out, out); |
| 6131 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6132 | __ j(kEqual, &done); |
| 6133 | if (cls.IsRegister()) { |
| 6134 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6135 | } else { |
| 6136 | DCHECK(cls.IsStackSlot()) << cls; |
| 6137 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6138 | } |
| 6139 | __ j(kNotEqual, &loop); |
| 6140 | __ movl(out, Immediate(1)); |
| 6141 | if (zero.IsLinked()) { |
| 6142 | __ jmp(&done); |
| 6143 | } |
| 6144 | break; |
| 6145 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6146 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6147 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6148 | // Walk over the class hierarchy to find a match. |
| 6149 | NearLabel loop, success; |
| 6150 | __ Bind(&loop); |
| 6151 | if (cls.IsRegister()) { |
| 6152 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6153 | } else { |
| 6154 | DCHECK(cls.IsStackSlot()) << cls; |
| 6155 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6156 | } |
| 6157 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6158 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6159 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6160 | __ testl(out, out); |
| 6161 | __ j(kNotEqual, &loop); |
| 6162 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6163 | __ jmp(&done); |
| 6164 | __ Bind(&success); |
| 6165 | __ movl(out, Immediate(1)); |
| 6166 | if (zero.IsLinked()) { |
| 6167 | __ jmp(&done); |
| 6168 | } |
| 6169 | break; |
| 6170 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6171 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6172 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6173 | // Do an exact check. |
| 6174 | NearLabel exact_check; |
| 6175 | if (cls.IsRegister()) { |
| 6176 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6177 | } else { |
| 6178 | DCHECK(cls.IsStackSlot()) << cls; |
| 6179 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6180 | } |
| 6181 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6182 | // 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] | 6183 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6184 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6185 | __ testl(out, out); |
| 6186 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6187 | __ j(kEqual, &done); |
| 6188 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6189 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6190 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6191 | __ movl(out, Immediate(1)); |
| 6192 | __ jmp(&done); |
| 6193 | break; |
| 6194 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6195 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6196 | case TypeCheckKind::kArrayCheck: { |
| 6197 | if (cls.IsRegister()) { |
| 6198 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6199 | } else { |
| 6200 | DCHECK(cls.IsStackSlot()) << cls; |
| 6201 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6202 | } |
| 6203 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6204 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6205 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6206 | codegen_->AddSlowPath(slow_path); |
| 6207 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6208 | __ movl(out, Immediate(1)); |
| 6209 | if (zero.IsLinked()) { |
| 6210 | __ jmp(&done); |
| 6211 | } |
| 6212 | break; |
| 6213 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6214 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6215 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6216 | case TypeCheckKind::kInterfaceCheck: { |
| 6217 | // 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] | 6218 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6219 | // cases. |
| 6220 | // |
| 6221 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6222 | // entry point without resorting to a type checking slow path |
| 6223 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6224 | // require to assign fixed registers for the inputs of this |
| 6225 | // HInstanceOf instruction (following the runtime calling |
| 6226 | // convention), which might be cluttered by the potential first |
| 6227 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6228 | // |
| 6229 | // TODO: Introduce a new runtime entry point taking the object |
| 6230 | // to test (instead of its class) as argument, and let it deal |
| 6231 | // with the read barrier issues. This will let us refactor this |
| 6232 | // case of the `switch` code as it was previously (with a direct |
| 6233 | // call to the runtime not using a type checking slow path). |
| 6234 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6235 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6236 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6237 | /* is_fatal */ false); |
| 6238 | codegen_->AddSlowPath(slow_path); |
| 6239 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6240 | if (zero.IsLinked()) { |
| 6241 | __ jmp(&done); |
| 6242 | } |
| 6243 | break; |
| 6244 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6245 | } |
| 6246 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6247 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6248 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6249 | __ xorl(out, out); |
| 6250 | } |
| 6251 | |
| 6252 | if (done.IsLinked()) { |
| 6253 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6254 | } |
| 6255 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6256 | if (slow_path != nullptr) { |
| 6257 | __ Bind(slow_path->GetExitLabel()); |
| 6258 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6259 | } |
| 6260 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6261 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6262 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6263 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6264 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6265 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6266 | case TypeCheckKind::kExactCheck: |
| 6267 | case TypeCheckKind::kAbstractClassCheck: |
| 6268 | case TypeCheckKind::kClassHierarchyCheck: |
| 6269 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6270 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6271 | LocationSummary::kCallOnSlowPath : |
| 6272 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6273 | break; |
| 6274 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6275 | case TypeCheckKind::kUnresolvedCheck: |
| 6276 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6277 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6278 | break; |
| 6279 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6280 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6281 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6282 | locations->SetInAt(1, Location::Any()); |
| 6283 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6284 | locations->AddTemp(Location::RequiresRegister()); |
| 6285 | // When read barriers are enabled, we need an additional temporary |
| 6286 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6287 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6288 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6289 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6293 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6294 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6295 | Location obj_loc = locations->InAt(0); |
| 6296 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6297 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6298 | Location temp_loc = locations->GetTemp(0); |
| 6299 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6300 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6301 | locations->GetTemp(1) : |
| 6302 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6303 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6304 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6305 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6306 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6307 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6308 | bool is_type_check_slow_path_fatal = |
| 6309 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6310 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6311 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6312 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6313 | !instruction->CanThrowIntoCatchBlock(); |
| 6314 | SlowPathCode* type_check_slow_path = |
| 6315 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6316 | is_type_check_slow_path_fatal); |
| 6317 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6318 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6319 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6320 | // Avoid null check if we know obj is not null. |
| 6321 | if (instruction->MustDoNullCheck()) { |
| 6322 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6323 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6324 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6325 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6326 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6327 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6328 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6329 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6330 | case TypeCheckKind::kExactCheck: |
| 6331 | case TypeCheckKind::kArrayCheck: { |
| 6332 | if (cls.IsRegister()) { |
| 6333 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6334 | } else { |
| 6335 | DCHECK(cls.IsStackSlot()) << cls; |
| 6336 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6337 | } |
| 6338 | // Jump to slow path for throwing the exception or doing a |
| 6339 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6340 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6341 | break; |
| 6342 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6343 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6344 | case TypeCheckKind::kAbstractClassCheck: { |
| 6345 | // If the class is abstract, we eagerly fetch the super class of the |
| 6346 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6347 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6348 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6349 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6350 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6351 | |
| 6352 | // If the class reference currently in `temp` is not null, jump |
| 6353 | // to the `compare_classes` label to compare it with the checked |
| 6354 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6355 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6356 | __ j(kNotEqual, &compare_classes); |
| 6357 | // Otherwise, jump to the slow path to throw the exception. |
| 6358 | // |
| 6359 | // But before, move back the object's class into `temp` before |
| 6360 | // going into the slow path, as it has been overwritten in the |
| 6361 | // meantime. |
| 6362 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6363 | GenerateReferenceLoadTwoRegisters( |
| 6364 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6365 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6366 | |
| 6367 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6368 | if (cls.IsRegister()) { |
| 6369 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6370 | } else { |
| 6371 | DCHECK(cls.IsStackSlot()) << cls; |
| 6372 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6373 | } |
| 6374 | __ j(kNotEqual, &loop); |
| 6375 | break; |
| 6376 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6377 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6378 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6379 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6380 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6381 | __ Bind(&loop); |
| 6382 | if (cls.IsRegister()) { |
| 6383 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6384 | } else { |
| 6385 | DCHECK(cls.IsStackSlot()) << cls; |
| 6386 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6387 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6388 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6389 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6390 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6391 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6392 | |
| 6393 | // If the class reference currently in `temp` is not null, jump |
| 6394 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6395 | __ testl(temp, temp); |
| 6396 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6397 | // Otherwise, jump to the slow path to throw the exception. |
| 6398 | // |
| 6399 | // But before, move back the object's class into `temp` before |
| 6400 | // going into the slow path, as it has been overwritten in the |
| 6401 | // meantime. |
| 6402 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6403 | GenerateReferenceLoadTwoRegisters( |
| 6404 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6405 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6406 | break; |
| 6407 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6408 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6409 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6410 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6411 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6412 | if (cls.IsRegister()) { |
| 6413 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6414 | } else { |
| 6415 | DCHECK(cls.IsStackSlot()) << cls; |
| 6416 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6417 | } |
| 6418 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6419 | |
| 6420 | // 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] | 6421 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6422 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6423 | |
| 6424 | // If the component type is not null (i.e. the object is indeed |
| 6425 | // an array), jump to label `check_non_primitive_component_type` |
| 6426 | // to further check that this component type is not a primitive |
| 6427 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6428 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6429 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6430 | // Otherwise, jump to the slow path to throw the exception. |
| 6431 | // |
| 6432 | // But before, move back the object's class into `temp` before |
| 6433 | // going into the slow path, as it has been overwritten in the |
| 6434 | // meantime. |
| 6435 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6436 | GenerateReferenceLoadTwoRegisters( |
| 6437 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6438 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6439 | |
| 6440 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6441 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6442 | __ j(kEqual, &done); |
| 6443 | // Same comment as above regarding `temp` and the slow path. |
| 6444 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6445 | GenerateReferenceLoadTwoRegisters( |
| 6446 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6447 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6448 | break; |
| 6449 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6450 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6451 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6452 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6453 | // We always go into the type check slow path for the unresolved |
| 6454 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6455 | // |
| 6456 | // We cannot directly call the CheckCast runtime entry point |
| 6457 | // without resorting to a type checking slow path here (i.e. by |
| 6458 | // calling InvokeRuntime directly), as it would require to |
| 6459 | // assign fixed registers for the inputs of this HInstanceOf |
| 6460 | // instruction (following the runtime calling convention), which |
| 6461 | // might be cluttered by the potential first read barrier |
| 6462 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6463 | // |
| 6464 | // TODO: Introduce a new runtime entry point taking the object |
| 6465 | // to test (instead of its class) as argument, and let it deal |
| 6466 | // with the read barrier issues. This will let us refactor this |
| 6467 | // case of the `switch` code as it was previously (with a direct |
| 6468 | // call to the runtime not using a type checking slow path). |
| 6469 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6470 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6471 | break; |
| 6472 | } |
| 6473 | __ Bind(&done); |
| 6474 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6475 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6476 | } |
| 6477 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6478 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6479 | LocationSummary* locations = |
| 6480 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6481 | InvokeRuntimeCallingConvention calling_convention; |
| 6482 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6483 | } |
| 6484 | |
| 6485 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6486 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6487 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6488 | instruction, |
| 6489 | instruction->GetDexPc(), |
| 6490 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6491 | if (instruction->IsEnter()) { |
| 6492 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6493 | } else { |
| 6494 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6495 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6496 | } |
| 6497 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6498 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6499 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6500 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6501 | |
| 6502 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6503 | LocationSummary* locations = |
| 6504 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6505 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6506 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6507 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6508 | locations->SetInAt(1, Location::Any()); |
| 6509 | locations->SetOut(Location::SameAsFirstInput()); |
| 6510 | } |
| 6511 | |
| 6512 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6513 | HandleBitwiseOperation(instruction); |
| 6514 | } |
| 6515 | |
| 6516 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6517 | HandleBitwiseOperation(instruction); |
| 6518 | } |
| 6519 | |
| 6520 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6521 | HandleBitwiseOperation(instruction); |
| 6522 | } |
| 6523 | |
| 6524 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6525 | LocationSummary* locations = instruction->GetLocations(); |
| 6526 | Location first = locations->InAt(0); |
| 6527 | Location second = locations->InAt(1); |
| 6528 | DCHECK(first.Equals(locations->Out())); |
| 6529 | |
| 6530 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6531 | if (second.IsRegister()) { |
| 6532 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6533 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6534 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6535 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6536 | } else { |
| 6537 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6538 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6539 | } |
| 6540 | } else if (second.IsConstant()) { |
| 6541 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6542 | __ andl(first.AsRegister<Register>(), |
| 6543 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6544 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6545 | __ orl(first.AsRegister<Register>(), |
| 6546 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6547 | } else { |
| 6548 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6549 | __ xorl(first.AsRegister<Register>(), |
| 6550 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6551 | } |
| 6552 | } else { |
| 6553 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6554 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6555 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6556 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6557 | } else { |
| 6558 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6559 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6560 | } |
| 6561 | } |
| 6562 | } else { |
| 6563 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6564 | if (second.IsRegisterPair()) { |
| 6565 | if (instruction->IsAnd()) { |
| 6566 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6567 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6568 | } else if (instruction->IsOr()) { |
| 6569 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6570 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6571 | } else { |
| 6572 | DCHECK(instruction->IsXor()); |
| 6573 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6574 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6575 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6576 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6577 | if (instruction->IsAnd()) { |
| 6578 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6579 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6580 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6581 | } else if (instruction->IsOr()) { |
| 6582 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6583 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6584 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6585 | } else { |
| 6586 | DCHECK(instruction->IsXor()); |
| 6587 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6588 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6589 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6590 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6591 | } else { |
| 6592 | DCHECK(second.IsConstant()) << second; |
| 6593 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6594 | int32_t low_value = Low32Bits(value); |
| 6595 | int32_t high_value = High32Bits(value); |
| 6596 | Immediate low(low_value); |
| 6597 | Immediate high(high_value); |
| 6598 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6599 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6600 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6601 | if (low_value == 0) { |
| 6602 | __ xorl(first_low, first_low); |
| 6603 | } else if (low_value != -1) { |
| 6604 | __ andl(first_low, low); |
| 6605 | } |
| 6606 | if (high_value == 0) { |
| 6607 | __ xorl(first_high, first_high); |
| 6608 | } else if (high_value != -1) { |
| 6609 | __ andl(first_high, high); |
| 6610 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6611 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6612 | if (low_value != 0) { |
| 6613 | __ orl(first_low, low); |
| 6614 | } |
| 6615 | if (high_value != 0) { |
| 6616 | __ orl(first_high, high); |
| 6617 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6618 | } else { |
| 6619 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6620 | if (low_value != 0) { |
| 6621 | __ xorl(first_low, low); |
| 6622 | } |
| 6623 | if (high_value != 0) { |
| 6624 | __ xorl(first_high, high); |
| 6625 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6626 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6627 | } |
| 6628 | } |
| 6629 | } |
| 6630 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6631 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6632 | Location out, |
| 6633 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6634 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6635 | Register out_reg = out.AsRegister<Register>(); |
| 6636 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6637 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6638 | if (kUseBakerReadBarrier) { |
| 6639 | // Load with fast path based Baker's read barrier. |
| 6640 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6641 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6642 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6643 | } else { |
| 6644 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6645 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6646 | // in the following move operation, as we will need it for the |
| 6647 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6648 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6649 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6650 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6651 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6652 | } |
| 6653 | } else { |
| 6654 | // Plain load with no read barrier. |
| 6655 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6656 | __ movl(out_reg, Address(out_reg, offset)); |
| 6657 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6658 | } |
| 6659 | } |
| 6660 | |
| 6661 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6662 | Location out, |
| 6663 | Location obj, |
| 6664 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6665 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6666 | Register out_reg = out.AsRegister<Register>(); |
| 6667 | Register obj_reg = obj.AsRegister<Register>(); |
| 6668 | if (kEmitCompilerReadBarrier) { |
| 6669 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6670 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6671 | // Load with fast path based Baker's read barrier. |
| 6672 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6673 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6674 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6675 | } else { |
| 6676 | // Load with slow path based read barrier. |
| 6677 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6678 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6679 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6680 | } |
| 6681 | } else { |
| 6682 | // Plain load with no read barrier. |
| 6683 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6684 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6685 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6686 | } |
| 6687 | } |
| 6688 | |
| 6689 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6690 | Location root, |
| 6691 | Register obj, |
| 6692 | uint32_t offset) { |
| 6693 | Register root_reg = root.AsRegister<Register>(); |
| 6694 | if (kEmitCompilerReadBarrier) { |
| 6695 | if (kUseBakerReadBarrier) { |
| 6696 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6697 | // Baker's read barrier are used: |
| 6698 | // |
| 6699 | // root = obj.field; |
| 6700 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6701 | // root = ReadBarrier::Mark(root) |
| 6702 | // } |
| 6703 | |
| 6704 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6705 | __ movl(root_reg, Address(obj, offset)); |
| 6706 | static_assert( |
| 6707 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6708 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6709 | "have different sizes."); |
| 6710 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6711 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6712 | "have different sizes."); |
| 6713 | |
| 6714 | // Slow path used to mark the GC root `root`. |
| 6715 | SlowPathCode* slow_path = |
| 6716 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6717 | codegen_->AddSlowPath(slow_path); |
| 6718 | |
| 6719 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6720 | Immediate(0)); |
| 6721 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6722 | __ Bind(slow_path->GetExitLabel()); |
| 6723 | } else { |
| 6724 | // GC root loaded through a slow path for read barriers other |
| 6725 | // than Baker's. |
| 6726 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6727 | __ leal(root_reg, Address(obj, offset)); |
| 6728 | // /* mirror::Object* */ root = root->Read() |
| 6729 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6730 | } |
| 6731 | } else { |
| 6732 | // Plain GC root load with no read barrier. |
| 6733 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6734 | __ movl(root_reg, Address(obj, offset)); |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6735 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6736 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6737 | } |
| 6738 | } |
| 6739 | |
| 6740 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6741 | Location ref, |
| 6742 | Register obj, |
| 6743 | uint32_t offset, |
| 6744 | Location temp, |
| 6745 | bool needs_null_check) { |
| 6746 | DCHECK(kEmitCompilerReadBarrier); |
| 6747 | DCHECK(kUseBakerReadBarrier); |
| 6748 | |
| 6749 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6750 | Address src(obj, offset); |
| 6751 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6752 | } |
| 6753 | |
| 6754 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6755 | Location ref, |
| 6756 | Register obj, |
| 6757 | uint32_t data_offset, |
| 6758 | Location index, |
| 6759 | Location temp, |
| 6760 | bool needs_null_check) { |
| 6761 | DCHECK(kEmitCompilerReadBarrier); |
| 6762 | DCHECK(kUseBakerReadBarrier); |
| 6763 | |
| 6764 | // /* HeapReference<Object> */ ref = |
| 6765 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6766 | Address src = index.IsConstant() ? |
| 6767 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6768 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6769 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6770 | } |
| 6771 | |
| 6772 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6773 | Location ref, |
| 6774 | Register obj, |
| 6775 | const Address& src, |
| 6776 | Location temp, |
| 6777 | bool needs_null_check) { |
| 6778 | DCHECK(kEmitCompilerReadBarrier); |
| 6779 | DCHECK(kUseBakerReadBarrier); |
| 6780 | |
| 6781 | // In slow path based read barriers, the read barrier call is |
| 6782 | // inserted after the original load. However, in fast path based |
| 6783 | // Baker's read barriers, we need to perform the load of |
| 6784 | // mirror::Object::monitor_ *before* the original reference load. |
| 6785 | // This load-load ordering is required by the read barrier. |
| 6786 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6787 | // |
| 6788 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6789 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6790 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6791 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6792 | // if (is_gray) { |
| 6793 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6794 | // } |
| 6795 | // |
| 6796 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6797 | // slightly more complex as: |
| 6798 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6799 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6800 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6801 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6802 | // - it performs additional checks that we do not do here for |
| 6803 | // performance reasons. |
| 6804 | |
| 6805 | Register ref_reg = ref.AsRegister<Register>(); |
| 6806 | Register temp_reg = temp.AsRegister<Register>(); |
| 6807 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6808 | |
| 6809 | // /* int32_t */ monitor = obj->monitor_ |
| 6810 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6811 | if (needs_null_check) { |
| 6812 | MaybeRecordImplicitNullCheck(instruction); |
| 6813 | } |
| 6814 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6815 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6816 | "art::LockWord and int32_t have different sizes."); |
| 6817 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6818 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6819 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6820 | static_assert( |
| 6821 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6822 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6823 | |
| 6824 | // Load fence to prevent load-load reordering. |
| 6825 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6826 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6827 | |
| 6828 | // The actual reference load. |
| 6829 | // /* HeapReference<Object> */ ref = *src |
| 6830 | __ movl(ref_reg, src); |
| 6831 | |
| 6832 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6833 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6834 | |
| 6835 | // Slow path used to mark the object `ref` when it is gray. |
| 6836 | SlowPathCode* slow_path = |
| 6837 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6838 | AddSlowPath(slow_path); |
| 6839 | |
| 6840 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6841 | // ref = ReadBarrier::Mark(ref); |
| 6842 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6843 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6844 | __ Bind(slow_path->GetExitLabel()); |
| 6845 | } |
| 6846 | |
| 6847 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6848 | Location out, |
| 6849 | Location ref, |
| 6850 | Location obj, |
| 6851 | uint32_t offset, |
| 6852 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6853 | DCHECK(kEmitCompilerReadBarrier); |
| 6854 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6855 | // Insert a slow path based read barrier *after* the reference load. |
| 6856 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6857 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6858 | // reference will be carried out by the runtime within the slow |
| 6859 | // path. |
| 6860 | // |
| 6861 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6862 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6863 | // not used by the artReadBarrierSlow entry point. |
| 6864 | // |
| 6865 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6866 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6867 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6868 | AddSlowPath(slow_path); |
| 6869 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6870 | __ jmp(slow_path->GetEntryLabel()); |
| 6871 | __ Bind(slow_path->GetExitLabel()); |
| 6872 | } |
| 6873 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6874 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6875 | Location out, |
| 6876 | Location ref, |
| 6877 | Location obj, |
| 6878 | uint32_t offset, |
| 6879 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6880 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6881 | // Baker's read barriers shall be handled by the fast path |
| 6882 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6883 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6884 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6885 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6886 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6887 | } else if (kPoisonHeapReferences) { |
| 6888 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6889 | } |
| 6890 | } |
| 6891 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6892 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6893 | Location out, |
| 6894 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6895 | DCHECK(kEmitCompilerReadBarrier); |
| 6896 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6897 | // Insert a slow path based read barrier *after* the GC root load. |
| 6898 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6899 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6900 | // not need to do anything special for this here. |
| 6901 | SlowPathCode* slow_path = |
| 6902 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6903 | AddSlowPath(slow_path); |
| 6904 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6905 | __ jmp(slow_path->GetEntryLabel()); |
| 6906 | __ Bind(slow_path->GetExitLabel()); |
| 6907 | } |
| 6908 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6909 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6910 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6911 | LOG(FATAL) << "Unreachable"; |
| 6912 | } |
| 6913 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6914 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6915 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6916 | LOG(FATAL) << "Unreachable"; |
| 6917 | } |
| 6918 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6919 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6920 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6921 | LocationSummary* locations = |
| 6922 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6923 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6924 | } |
| 6925 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6926 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6927 | int32_t lower_bound, |
| 6928 | uint32_t num_entries, |
| 6929 | HBasicBlock* switch_block, |
| 6930 | HBasicBlock* default_block) { |
| 6931 | // Figure out the correct compare values and jump conditions. |
| 6932 | // Handle the first compare/branch as a special case because it might |
| 6933 | // jump to the default case. |
| 6934 | DCHECK_GT(num_entries, 2u); |
| 6935 | Condition first_condition; |
| 6936 | uint32_t index; |
| 6937 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6938 | if (lower_bound != 0) { |
| 6939 | first_condition = kLess; |
| 6940 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6941 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6942 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6943 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6944 | index = 1; |
| 6945 | } else { |
| 6946 | // Handle all the compare/jumps below. |
| 6947 | first_condition = kBelow; |
| 6948 | index = 0; |
| 6949 | } |
| 6950 | |
| 6951 | // Handle the rest of the compare/jumps. |
| 6952 | for (; index + 1 < num_entries; index += 2) { |
| 6953 | int32_t compare_to_value = lower_bound + index + 1; |
| 6954 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6955 | // Jump to successors[index] if value < case_value[index]. |
| 6956 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6957 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6958 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6959 | } |
| 6960 | |
| 6961 | if (index != num_entries) { |
| 6962 | // There are an odd number of entries. Handle the last one. |
| 6963 | DCHECK_EQ(index + 1, num_entries); |
| 6964 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6965 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6966 | } |
| 6967 | |
| 6968 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6969 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6970 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6971 | } |
| 6972 | } |
| 6973 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6974 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6975 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6976 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6977 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6978 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6979 | |
| 6980 | GenPackedSwitchWithCompares(value_reg, |
| 6981 | lower_bound, |
| 6982 | num_entries, |
| 6983 | switch_instr->GetBlock(), |
| 6984 | switch_instr->GetDefaultBlock()); |
| 6985 | } |
| 6986 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6987 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6988 | LocationSummary* locations = |
| 6989 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6990 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6991 | |
| 6992 | // Constant area pointer. |
| 6993 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6994 | |
| 6995 | // And the temporary we need. |
| 6996 | locations->AddTemp(Location::RequiresRegister()); |
| 6997 | } |
| 6998 | |
| 6999 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7000 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7001 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7002 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7003 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7004 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7005 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7006 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7007 | GenPackedSwitchWithCompares(value_reg, |
| 7008 | lower_bound, |
| 7009 | num_entries, |
| 7010 | switch_instr->GetBlock(), |
| 7011 | default_block); |
| 7012 | return; |
| 7013 | } |
| 7014 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7015 | // Optimizing has a jump area. |
| 7016 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7017 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7018 | |
| 7019 | // Remove the bias, if needed. |
| 7020 | if (lower_bound != 0) { |
| 7021 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7022 | value_reg = temp_reg; |
| 7023 | } |
| 7024 | |
| 7025 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7026 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7027 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7028 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7029 | |
| 7030 | // We are in the range of the table. |
| 7031 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7032 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7033 | |
| 7034 | // Compute the actual target address by adding in constant_area. |
| 7035 | __ addl(temp_reg, constant_area); |
| 7036 | |
| 7037 | // And jump. |
| 7038 | __ jmp(temp_reg); |
| 7039 | } |
| 7040 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7041 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7042 | HX86ComputeBaseMethodAddress* insn) { |
| 7043 | LocationSummary* locations = |
| 7044 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7045 | locations->SetOut(Location::RequiresRegister()); |
| 7046 | } |
| 7047 | |
| 7048 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7049 | HX86ComputeBaseMethodAddress* insn) { |
| 7050 | LocationSummary* locations = insn->GetLocations(); |
| 7051 | Register reg = locations->Out().AsRegister<Register>(); |
| 7052 | |
| 7053 | // Generate call to next instruction. |
| 7054 | Label next_instruction; |
| 7055 | __ call(&next_instruction); |
| 7056 | __ Bind(&next_instruction); |
| 7057 | |
| 7058 | // Remember this offset for later use with constant area. |
| 7059 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7060 | |
| 7061 | // Grab the return address off the stack. |
| 7062 | __ popl(reg); |
| 7063 | } |
| 7064 | |
| 7065 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7066 | HX86LoadFromConstantTable* insn) { |
| 7067 | LocationSummary* locations = |
| 7068 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7069 | |
| 7070 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7071 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7072 | |
| 7073 | // 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] | 7074 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7075 | return; |
| 7076 | } |
| 7077 | |
| 7078 | switch (insn->GetType()) { |
| 7079 | case Primitive::kPrimFloat: |
| 7080 | case Primitive::kPrimDouble: |
| 7081 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7082 | break; |
| 7083 | |
| 7084 | case Primitive::kPrimInt: |
| 7085 | locations->SetOut(Location::RequiresRegister()); |
| 7086 | break; |
| 7087 | |
| 7088 | default: |
| 7089 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7090 | } |
| 7091 | } |
| 7092 | |
| 7093 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7094 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7095 | return; |
| 7096 | } |
| 7097 | |
| 7098 | LocationSummary* locations = insn->GetLocations(); |
| 7099 | Location out = locations->Out(); |
| 7100 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7101 | HConstant *value = insn->GetConstant(); |
| 7102 | |
| 7103 | switch (insn->GetType()) { |
| 7104 | case Primitive::kPrimFloat: |
| 7105 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7106 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7107 | break; |
| 7108 | |
| 7109 | case Primitive::kPrimDouble: |
| 7110 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7111 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7112 | break; |
| 7113 | |
| 7114 | case Primitive::kPrimInt: |
| 7115 | __ movl(out.AsRegister<Register>(), |
| 7116 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7117 | break; |
| 7118 | |
| 7119 | default: |
| 7120 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7121 | } |
| 7122 | } |
| 7123 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7124 | /** |
| 7125 | * Class to handle late fixup of offsets into constant area. |
| 7126 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7127 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7128 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7129 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7130 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7131 | |
| 7132 | protected: |
| 7133 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7134 | |
| 7135 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7136 | |
| 7137 | private: |
| 7138 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7139 | // Patch the correct offset for the instruction. The place to patch is the |
| 7140 | // last 4 bytes of the instruction. |
| 7141 | // The value to patch is the distance from the offset in the constant area |
| 7142 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7143 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7144 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7145 | |
| 7146 | // Patch in the right value. |
| 7147 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7148 | } |
| 7149 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7150 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7151 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7152 | }; |
| 7153 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7154 | /** |
| 7155 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7156 | * constant area. |
| 7157 | */ |
| 7158 | class JumpTableRIPFixup : public RIPFixup { |
| 7159 | public: |
| 7160 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7161 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7162 | |
| 7163 | void CreateJumpTable() { |
| 7164 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7165 | |
| 7166 | // Ensure that the reference to the jump table has the correct offset. |
| 7167 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7168 | SetOffset(offset_in_constant_table); |
| 7169 | |
| 7170 | // The label values in the jump table are computed relative to the |
| 7171 | // instruction addressing the constant area. |
| 7172 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7173 | |
| 7174 | // Populate the jump table with the correct values for the jump table. |
| 7175 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7176 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7177 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7178 | // The value that we want is the target offset - the position of the table. |
| 7179 | for (int32_t i = 0; i < num_entries; i++) { |
| 7180 | HBasicBlock* b = successors[i]; |
| 7181 | Label* l = codegen_->GetLabelOf(b); |
| 7182 | DCHECK(l->IsBound()); |
| 7183 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7184 | assembler->AppendInt32(offset_to_block); |
| 7185 | } |
| 7186 | } |
| 7187 | |
| 7188 | private: |
| 7189 | const HX86PackedSwitch* switch_instr_; |
| 7190 | }; |
| 7191 | |
| 7192 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7193 | // Generate the constant area if needed. |
| 7194 | X86Assembler* assembler = GetAssembler(); |
| 7195 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7196 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7197 | // byte values. |
| 7198 | assembler->Align(4, 0); |
| 7199 | constant_area_start_ = assembler->CodeSize(); |
| 7200 | |
| 7201 | // Populate any jump tables. |
| 7202 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7203 | jump_table->CreateJumpTable(); |
| 7204 | } |
| 7205 | |
| 7206 | // And now add the constant area to the generated code. |
| 7207 | assembler->AddConstantArea(); |
| 7208 | } |
| 7209 | |
| 7210 | // And finish up. |
| 7211 | CodeGenerator::Finalize(allocator); |
| 7212 | } |
| 7213 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7214 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7215 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7216 | return Address(reg, kDummy32BitOffset, fixup); |
| 7217 | } |
| 7218 | |
| 7219 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7220 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7221 | return Address(reg, kDummy32BitOffset, fixup); |
| 7222 | } |
| 7223 | |
| 7224 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7225 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7226 | return Address(reg, kDummy32BitOffset, fixup); |
| 7227 | } |
| 7228 | |
| 7229 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7230 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7231 | return Address(reg, kDummy32BitOffset, fixup); |
| 7232 | } |
| 7233 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7234 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7235 | if (value == 0) { |
| 7236 | __ xorl(dest, dest); |
| 7237 | } else { |
| 7238 | __ movl(dest, Immediate(value)); |
| 7239 | } |
| 7240 | } |
| 7241 | |
| 7242 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7243 | if (value == 0) { |
| 7244 | __ testl(dest, dest); |
| 7245 | } else { |
| 7246 | __ cmpl(dest, Immediate(value)); |
| 7247 | } |
| 7248 | } |
| 7249 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7250 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7251 | Register reg, |
| 7252 | Register value) { |
| 7253 | // Create a fixup to be used to create and address the jump table. |
| 7254 | JumpTableRIPFixup* table_fixup = |
| 7255 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7256 | |
| 7257 | // We have to populate the jump tables. |
| 7258 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7259 | |
| 7260 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7261 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7262 | } |
| 7263 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7264 | // TODO: target as memory. |
| 7265 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7266 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7267 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7268 | return; |
| 7269 | } |
| 7270 | |
| 7271 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7272 | |
| 7273 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7274 | if (target.Equals(return_loc)) { |
| 7275 | return; |
| 7276 | } |
| 7277 | |
| 7278 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7279 | // with the else branch. |
| 7280 | if (type == Primitive::kPrimLong) { |
| 7281 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7282 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7283 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7284 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7285 | } else { |
| 7286 | // Let the parallel move resolver take care of all of this. |
| 7287 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7288 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7289 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7290 | } |
| 7291 | } |
| 7292 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7293 | #undef __ |
| 7294 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7295 | } // namespace x86 |
| 7296 | } // namespace art |