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" |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 29 | #include "pc_relative_fixups_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 34 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 38 | template<class MirrorType> |
| 39 | class GcRoot; |
| 40 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 41 | namespace x86 { |
| 42 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 43 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 45 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 46 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 47 | static constexpr int kC2ConditionMask = 0x400; |
| 48 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 49 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 50 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 51 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 52 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 54 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 56 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 57 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 58 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 59 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 60 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 61 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 62 | // Live registers will be restored in the catch block if caught. |
| 63 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 64 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 65 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 66 | instruction_, |
| 67 | instruction_->GetDexPc(), |
| 68 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 69 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 72 | bool IsFatal() const OVERRIDE { return true; } |
| 73 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 74 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 75 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 76 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 77 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 79 | }; |
| 80 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 81 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 82 | public: |
| 83 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 84 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 85 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 86 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 87 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 88 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 89 | // Live registers will be restored in the catch block if caught. |
| 90 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 91 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 92 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 93 | instruction_, |
| 94 | instruction_->GetDexPc(), |
| 95 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 96 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 99 | bool IsFatal() const OVERRIDE { return true; } |
| 100 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 101 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 102 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | private: |
| 104 | HDivZeroCheck* const instruction_; |
| 105 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 106 | }; |
| 107 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 108 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 110 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 111 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 112 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 114 | if (is_div_) { |
| 115 | __ negl(reg_); |
| 116 | } else { |
| 117 | __ movl(reg_, Immediate(0)); |
| 118 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 119 | __ jmp(GetExitLabel()); |
| 120 | } |
| 121 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 122 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 123 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | private: |
| 125 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 126 | bool is_div_; |
| 127 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 130 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 131 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 132 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 134 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 135 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 136 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 137 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 138 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 139 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 140 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 141 | // Live registers will be restored in the catch block if caught. |
| 142 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 143 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 144 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 145 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 146 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 147 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 148 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 149 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 150 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 151 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 152 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 153 | instruction_, |
| 154 | instruction_->GetDexPc(), |
| 155 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 156 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 159 | bool IsFatal() const OVERRIDE { return true; } |
| 160 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 161 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 162 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 163 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 164 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 165 | |
| 166 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 167 | }; |
| 168 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 169 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 170 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 171 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 172 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 173 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 174 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 175 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 176 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 177 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 178 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 179 | instruction_, |
| 180 | instruction_->GetDexPc(), |
| 181 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 182 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 183 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 184 | if (successor_ == nullptr) { |
| 185 | __ jmp(GetReturnLabel()); |
| 186 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 187 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 188 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 191 | Label* GetReturnLabel() { |
| 192 | DCHECK(successor_ == nullptr); |
| 193 | return &return_label_; |
| 194 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 195 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 196 | HBasicBlock* GetSuccessor() const { |
| 197 | return successor_; |
| 198 | } |
| 199 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 200 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 201 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 202 | private: |
| 203 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 204 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 205 | Label return_label_; |
| 206 | |
| 207 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 208 | }; |
| 209 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 210 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 211 | public: |
| 212 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 213 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 214 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 215 | LocationSummary* locations = instruction_->GetLocations(); |
| 216 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 217 | |
| 218 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 219 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 220 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 221 | |
| 222 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 223 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 224 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 225 | instruction_, |
| 226 | instruction_->GetDexPc(), |
| 227 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 228 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 229 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 230 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 231 | |
| 232 | __ jmp(GetExitLabel()); |
| 233 | } |
| 234 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 235 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 236 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 237 | private: |
| 238 | HLoadString* const instruction_; |
| 239 | |
| 240 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 241 | }; |
| 242 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 243 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 244 | public: |
| 245 | LoadClassSlowPathX86(HLoadClass* cls, |
| 246 | HInstruction* at, |
| 247 | uint32_t dex_pc, |
| 248 | bool do_clinit) |
| 249 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 250 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 251 | } |
| 252 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 253 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 254 | LocationSummary* locations = at_->GetLocations(); |
| 255 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 256 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 257 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 258 | |
| 259 | InvokeRuntimeCallingConvention calling_convention; |
| 260 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 261 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 262 | : QUICK_ENTRY_POINT(pInitializeType), |
| 263 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 264 | if (do_clinit_) { |
| 265 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 266 | } else { |
| 267 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 268 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | |
| 270 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 271 | Location out = locations->Out(); |
| 272 | if (out.IsValid()) { |
| 273 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 274 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 275 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 276 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 277 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 278 | __ jmp(GetExitLabel()); |
| 279 | } |
| 280 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 281 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 282 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 | private: |
| 284 | // The class this slow path will load. |
| 285 | HLoadClass* const cls_; |
| 286 | |
| 287 | // The instruction where this slow path is happening. |
| 288 | // (Might be the load class or an initialization check). |
| 289 | HInstruction* const at_; |
| 290 | |
| 291 | // The dex PC of `at_`. |
| 292 | const uint32_t dex_pc_; |
| 293 | |
| 294 | // Whether to initialize the class. |
| 295 | const bool do_clinit_; |
| 296 | |
| 297 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 298 | }; |
| 299 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 300 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 302 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| 303 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 304 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 305 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 307 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 308 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 309 | DCHECK(instruction_->IsCheckCast() |
| 310 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 311 | |
| 312 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 313 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 314 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 315 | if (!is_fatal_) { |
| 316 | SaveLiveRegisters(codegen, locations); |
| 317 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 318 | |
| 319 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 320 | // move resolver. |
| 321 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 322 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 323 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 324 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 325 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 326 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 327 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 328 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 330 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 331 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 332 | instruction_, |
| 333 | instruction_->GetDexPc(), |
| 334 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 335 | CheckEntrypointTypes< |
| 336 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 337 | } else { |
| 338 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 339 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 340 | instruction_, |
| 341 | instruction_->GetDexPc(), |
| 342 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 343 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 346 | if (!is_fatal_) { |
| 347 | if (instruction_->IsInstanceOf()) { |
| 348 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 349 | } |
| 350 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 351 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 352 | __ jmp(GetExitLabel()); |
| 353 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 356 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 357 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 358 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 359 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 360 | HInstruction* const instruction_; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 361 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 362 | |
| 363 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 364 | }; |
| 365 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 366 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 367 | public: |
| 368 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 369 | : instruction_(instruction) {} |
| 370 | |
| 371 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 9859620 | 2015-08-19 11:33:36 +0100 | [diff] [blame] | 372 | DCHECK(instruction_->IsDeoptimize()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 373 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 374 | __ Bind(GetEntryLabel()); |
| 375 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 376 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 377 | instruction_, |
| 378 | instruction_->GetDexPc(), |
| 379 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 380 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 383 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 384 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 385 | private: |
| 386 | HInstruction* const instruction_; |
| 387 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 388 | }; |
| 389 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 390 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 391 | public: |
| 392 | explicit ArraySetSlowPathX86(HInstruction* instruction) : instruction_(instruction) {} |
| 393 | |
| 394 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 395 | LocationSummary* locations = instruction_->GetLocations(); |
| 396 | __ Bind(GetEntryLabel()); |
| 397 | SaveLiveRegisters(codegen, locations); |
| 398 | |
| 399 | InvokeRuntimeCallingConvention calling_convention; |
| 400 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 401 | parallel_move.AddMove( |
| 402 | locations->InAt(0), |
| 403 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 404 | Primitive::kPrimNot, |
| 405 | nullptr); |
| 406 | parallel_move.AddMove( |
| 407 | locations->InAt(1), |
| 408 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 409 | Primitive::kPrimInt, |
| 410 | nullptr); |
| 411 | parallel_move.AddMove( |
| 412 | locations->InAt(2), |
| 413 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 414 | Primitive::kPrimNot, |
| 415 | nullptr); |
| 416 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 417 | |
| 418 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 419 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 420 | instruction_, |
| 421 | instruction_->GetDexPc(), |
| 422 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 423 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 424 | RestoreLiveRegisters(codegen, locations); |
| 425 | __ jmp(GetExitLabel()); |
| 426 | } |
| 427 | |
| 428 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 429 | |
| 430 | private: |
| 431 | HInstruction* const instruction_; |
| 432 | |
| 433 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 434 | }; |
| 435 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 436 | // Slow path marking an object during a read barrier. |
| 437 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 438 | public: |
| 439 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location out, Location obj) |
| 440 | : instruction_(instruction), out_(out), obj_(obj) { |
| 441 | DCHECK(kEmitCompilerReadBarrier); |
| 442 | } |
| 443 | |
| 444 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 445 | |
| 446 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 447 | LocationSummary* locations = instruction_->GetLocations(); |
| 448 | Register reg_out = out_.AsRegister<Register>(); |
| 449 | DCHECK(locations->CanCall()); |
| 450 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 451 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 452 | instruction_->IsStaticFieldGet() || |
| 453 | instruction_->IsArrayGet() || |
| 454 | instruction_->IsLoadClass() || |
| 455 | instruction_->IsLoadString() || |
| 456 | instruction_->IsInstanceOf() || |
| 457 | instruction_->IsCheckCast()) |
| 458 | << "Unexpected instruction in read barrier marking slow path: " |
| 459 | << instruction_->DebugName(); |
| 460 | |
| 461 | __ Bind(GetEntryLabel()); |
| 462 | SaveLiveRegisters(codegen, locations); |
| 463 | |
| 464 | InvokeRuntimeCallingConvention calling_convention; |
| 465 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 466 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 467 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 468 | instruction_, |
| 469 | instruction_->GetDexPc(), |
| 470 | this); |
| 471 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 472 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 473 | |
| 474 | RestoreLiveRegisters(codegen, locations); |
| 475 | __ jmp(GetExitLabel()); |
| 476 | } |
| 477 | |
| 478 | private: |
| 479 | HInstruction* const instruction_; |
| 480 | const Location out_; |
| 481 | const Location obj_; |
| 482 | |
| 483 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 484 | }; |
| 485 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 486 | // Slow path generating a read barrier for a heap reference. |
| 487 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 488 | public: |
| 489 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 490 | Location out, |
| 491 | Location ref, |
| 492 | Location obj, |
| 493 | uint32_t offset, |
| 494 | Location index) |
| 495 | : instruction_(instruction), |
| 496 | out_(out), |
| 497 | ref_(ref), |
| 498 | obj_(obj), |
| 499 | offset_(offset), |
| 500 | index_(index) { |
| 501 | DCHECK(kEmitCompilerReadBarrier); |
| 502 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 503 | // has been overwritten by (or after) the heap object reference load |
| 504 | // to be instrumented, e.g.: |
| 505 | // |
| 506 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 507 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 508 | // |
| 509 | // In that case, we have lost the information about the original |
| 510 | // object, and the emitted read barrier cannot work properly. |
| 511 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 512 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 513 | } |
| 514 | |
| 515 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 516 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 517 | LocationSummary* locations = instruction_->GetLocations(); |
| 518 | Register reg_out = out_.AsRegister<Register>(); |
| 519 | DCHECK(locations->CanCall()); |
| 520 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 521 | DCHECK(!instruction_->IsInvoke() || |
| 522 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 523 | instruction_->GetLocations()->Intrinsified())) |
| 524 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 525 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 526 | |
| 527 | __ Bind(GetEntryLabel()); |
| 528 | SaveLiveRegisters(codegen, locations); |
| 529 | |
| 530 | // We may have to change the index's value, but as `index_` is a |
| 531 | // constant member (like other "inputs" of this slow path), |
| 532 | // introduce a copy of it, `index`. |
| 533 | Location index = index_; |
| 534 | if (index_.IsValid()) { |
| 535 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 536 | if (instruction_->IsArrayGet()) { |
| 537 | // Compute the actual memory offset and store it in `index`. |
| 538 | Register index_reg = index_.AsRegister<Register>(); |
| 539 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 540 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 541 | // We are about to change the value of `index_reg` (see the |
| 542 | // calls to art::x86::X86Assembler::shll and |
| 543 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 544 | // not been saved by the previous call to |
| 545 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 546 | // callee-save register -- |
| 547 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 548 | // callee-save registers, as it has been designed with the |
| 549 | // assumption that callee-save registers are supposed to be |
| 550 | // handled by the called function. So, as a callee-save |
| 551 | // register, `index_reg` _would_ eventually be saved onto |
| 552 | // the stack, but it would be too late: we would have |
| 553 | // changed its value earlier. Therefore, we manually save |
| 554 | // it here into another freely available register, |
| 555 | // `free_reg`, chosen of course among the caller-save |
| 556 | // registers (as a callee-save `free_reg` register would |
| 557 | // exhibit the same problem). |
| 558 | // |
| 559 | // Note we could have requested a temporary register from |
| 560 | // the register allocator instead; but we prefer not to, as |
| 561 | // this is a slow path, and we know we can find a |
| 562 | // caller-save register that is available. |
| 563 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 564 | __ movl(free_reg, index_reg); |
| 565 | index_reg = free_reg; |
| 566 | index = Location::RegisterLocation(index_reg); |
| 567 | } else { |
| 568 | // The initial register stored in `index_` has already been |
| 569 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 570 | // (as it is not a callee-save register), so we can freely |
| 571 | // use it. |
| 572 | } |
| 573 | // Shifting the index value contained in `index_reg` by the scale |
| 574 | // factor (2) cannot overflow in practice, as the runtime is |
| 575 | // unable to allocate object arrays with a size larger than |
| 576 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 577 | __ shll(index_reg, Immediate(TIMES_4)); |
| 578 | static_assert( |
| 579 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 580 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 581 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 582 | } else { |
| 583 | DCHECK(instruction_->IsInvoke()); |
| 584 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 585 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 586 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 587 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 588 | DCHECK_EQ(offset_, 0U); |
| 589 | DCHECK(index_.IsRegisterPair()); |
| 590 | // UnsafeGet's offset location is a register pair, the low |
| 591 | // part contains the correct offset. |
| 592 | index = index_.ToLow(); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | // We're moving two or three locations to locations that could |
| 597 | // overlap, so we need a parallel move resolver. |
| 598 | InvokeRuntimeCallingConvention calling_convention; |
| 599 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 600 | parallel_move.AddMove(ref_, |
| 601 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 602 | Primitive::kPrimNot, |
| 603 | nullptr); |
| 604 | parallel_move.AddMove(obj_, |
| 605 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 606 | Primitive::kPrimNot, |
| 607 | nullptr); |
| 608 | if (index.IsValid()) { |
| 609 | parallel_move.AddMove(index, |
| 610 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 611 | Primitive::kPrimInt, |
| 612 | nullptr); |
| 613 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 614 | } else { |
| 615 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 616 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 617 | } |
| 618 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 619 | instruction_, |
| 620 | instruction_->GetDexPc(), |
| 621 | this); |
| 622 | CheckEntrypointTypes< |
| 623 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 624 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 625 | |
| 626 | RestoreLiveRegisters(codegen, locations); |
| 627 | __ jmp(GetExitLabel()); |
| 628 | } |
| 629 | |
| 630 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 631 | |
| 632 | private: |
| 633 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 634 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 635 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 636 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 637 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 638 | return static_cast<Register>(i); |
| 639 | } |
| 640 | } |
| 641 | // We shall never fail to find a free caller-save register, as |
| 642 | // there are more than two core caller-save registers on x86 |
| 643 | // (meaning it is possible to find one which is different from |
| 644 | // `ref` and `obj`). |
| 645 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 646 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 647 | UNREACHABLE(); |
| 648 | } |
| 649 | |
| 650 | HInstruction* const instruction_; |
| 651 | const Location out_; |
| 652 | const Location ref_; |
| 653 | const Location obj_; |
| 654 | const uint32_t offset_; |
| 655 | // An additional location containing an index to an array. |
| 656 | // Only used for HArrayGet and the UnsafeGetObject & |
| 657 | // UnsafeGetObjectVolatile intrinsics. |
| 658 | const Location index_; |
| 659 | |
| 660 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 661 | }; |
| 662 | |
| 663 | // Slow path generating a read barrier for a GC root. |
| 664 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 665 | public: |
| 666 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 667 | : instruction_(instruction), out_(out), root_(root) { |
| 668 | DCHECK(kEmitCompilerReadBarrier); |
| 669 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 670 | |
| 671 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 672 | LocationSummary* locations = instruction_->GetLocations(); |
| 673 | Register reg_out = out_.AsRegister<Register>(); |
| 674 | DCHECK(locations->CanCall()); |
| 675 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 676 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 677 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 678 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 679 | |
| 680 | __ Bind(GetEntryLabel()); |
| 681 | SaveLiveRegisters(codegen, locations); |
| 682 | |
| 683 | InvokeRuntimeCallingConvention calling_convention; |
| 684 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 685 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 686 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 687 | instruction_, |
| 688 | instruction_->GetDexPc(), |
| 689 | this); |
| 690 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 691 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 692 | |
| 693 | RestoreLiveRegisters(codegen, locations); |
| 694 | __ jmp(GetExitLabel()); |
| 695 | } |
| 696 | |
| 697 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 698 | |
| 699 | private: |
| 700 | HInstruction* const instruction_; |
| 701 | const Location out_; |
| 702 | const Location root_; |
| 703 | |
| 704 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 705 | }; |
| 706 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 707 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 708 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 709 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 710 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 711 | switch (cond) { |
| 712 | case kCondEQ: return kEqual; |
| 713 | case kCondNE: return kNotEqual; |
| 714 | case kCondLT: return kLess; |
| 715 | case kCondLE: return kLessEqual; |
| 716 | case kCondGT: return kGreater; |
| 717 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 718 | case kCondB: return kBelow; |
| 719 | case kCondBE: return kBelowEqual; |
| 720 | case kCondA: return kAbove; |
| 721 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 722 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 723 | LOG(FATAL) << "Unreachable"; |
| 724 | UNREACHABLE(); |
| 725 | } |
| 726 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 727 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 728 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 729 | switch (cond) { |
| 730 | case kCondEQ: return kEqual; |
| 731 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 732 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 733 | case kCondLT: return kBelow; |
| 734 | case kCondLE: return kBelowEqual; |
| 735 | case kCondGT: return kAbove; |
| 736 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 737 | // Unsigned remain unchanged. |
| 738 | case kCondB: return kBelow; |
| 739 | case kCondBE: return kBelowEqual; |
| 740 | case kCondA: return kAbove; |
| 741 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 742 | } |
| 743 | LOG(FATAL) << "Unreachable"; |
| 744 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 747 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 748 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 752 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 753 | } |
| 754 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 755 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 756 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 757 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 758 | } |
| 759 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 760 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 761 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 762 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 765 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 766 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 767 | return GetFloatingPointSpillSlotSize(); |
| 768 | } |
| 769 | |
| 770 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 771 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 772 | return GetFloatingPointSpillSlotSize(); |
| 773 | } |
| 774 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 775 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 776 | HInstruction* instruction, |
| 777 | uint32_t dex_pc, |
| 778 | SlowPathCode* slow_path) { |
| 779 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 780 | instruction, |
| 781 | dex_pc, |
| 782 | slow_path); |
| 783 | } |
| 784 | |
| 785 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 786 | HInstruction* instruction, |
| 787 | uint32_t dex_pc, |
| 788 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 789 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 790 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 791 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 792 | } |
| 793 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 794 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 795 | const X86InstructionSetFeatures& isa_features, |
| 796 | const CompilerOptions& compiler_options, |
| 797 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 798 | : CodeGenerator(graph, |
| 799 | kNumberOfCpuRegisters, |
| 800 | kNumberOfXmmRegisters, |
| 801 | kNumberOfRegisterPairs, |
| 802 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 803 | arraysize(kCoreCalleeSaves)) |
| 804 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 805 | 0, |
| 806 | compiler_options, |
| 807 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 808 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 809 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 810 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 811 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 812 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 813 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 814 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 815 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 816 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 817 | // Use a fake return address register to mimic Quick. |
| 818 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 819 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 820 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 821 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 822 | switch (type) { |
| 823 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 824 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 825 | X86ManagedRegister pair = |
| 826 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 827 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 828 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 829 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 830 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 831 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 832 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | case Primitive::kPrimByte: |
| 836 | case Primitive::kPrimBoolean: |
| 837 | case Primitive::kPrimChar: |
| 838 | case Primitive::kPrimShort: |
| 839 | case Primitive::kPrimInt: |
| 840 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 841 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 842 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 843 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 844 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 845 | X86ManagedRegister current = |
| 846 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 847 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 848 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 849 | } |
| 850 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 851 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 855 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 856 | return Location::FpuRegisterLocation( |
| 857 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 858 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 859 | |
| 860 | case Primitive::kPrimVoid: |
| 861 | LOG(FATAL) << "Unreachable type " << type; |
| 862 | } |
| 863 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 864 | return Location::NoLocation(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 865 | } |
| 866 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 867 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 868 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 869 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 870 | |
| 871 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 872 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 873 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 874 | if (is_baseline) { |
| 875 | blocked_core_registers_[EBP] = true; |
| 876 | blocked_core_registers_[ESI] = true; |
| 877 | blocked_core_registers_[EDI] = true; |
| 878 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 879 | |
| 880 | UpdateBlockedPairRegisters(); |
| 881 | } |
| 882 | |
| 883 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 884 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 885 | X86ManagedRegister current = |
| 886 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 887 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 888 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 889 | blocked_register_pairs_[i] = true; |
| 890 | } |
| 891 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 892 | } |
| 893 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 894 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 895 | : HGraphVisitor(graph), |
| 896 | assembler_(codegen->GetAssembler()), |
| 897 | codegen_(codegen) {} |
| 898 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 899 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 900 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 901 | } |
| 902 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 903 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 904 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 905 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 906 | bool skip_overflow_check = |
| 907 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 908 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 909 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 910 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 911 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 912 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 913 | } |
| 914 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 915 | if (HasEmptyFrame()) { |
| 916 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 917 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 918 | |
| 919 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 920 | Register reg = kCoreCalleeSaves[i]; |
| 921 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 922 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 923 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 924 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 928 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 929 | __ subl(ESP, Immediate(adjust)); |
| 930 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 931 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 935 | __ cfi().RememberState(); |
| 936 | if (!HasEmptyFrame()) { |
| 937 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 938 | __ addl(ESP, Immediate(adjust)); |
| 939 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 940 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 941 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 942 | Register reg = kCoreCalleeSaves[i]; |
| 943 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 944 | __ popl(reg); |
| 945 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 946 | __ cfi().Restore(DWARFReg(reg)); |
| 947 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 948 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 949 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 950 | __ ret(); |
| 951 | __ cfi().RestoreState(); |
| 952 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 955 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 956 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 959 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 960 | switch (load->GetType()) { |
| 961 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 962 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 963 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 964 | |
| 965 | case Primitive::kPrimInt: |
| 966 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 967 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 968 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 969 | |
| 970 | case Primitive::kPrimBoolean: |
| 971 | case Primitive::kPrimByte: |
| 972 | case Primitive::kPrimChar: |
| 973 | case Primitive::kPrimShort: |
| 974 | case Primitive::kPrimVoid: |
| 975 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 976 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 980 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 981 | } |
| 982 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 983 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 984 | switch (type) { |
| 985 | case Primitive::kPrimBoolean: |
| 986 | case Primitive::kPrimByte: |
| 987 | case Primitive::kPrimChar: |
| 988 | case Primitive::kPrimShort: |
| 989 | case Primitive::kPrimInt: |
| 990 | case Primitive::kPrimNot: |
| 991 | return Location::RegisterLocation(EAX); |
| 992 | |
| 993 | case Primitive::kPrimLong: |
| 994 | return Location::RegisterPairLocation(EAX, EDX); |
| 995 | |
| 996 | case Primitive::kPrimVoid: |
| 997 | return Location::NoLocation(); |
| 998 | |
| 999 | case Primitive::kPrimDouble: |
| 1000 | case Primitive::kPrimFloat: |
| 1001 | return Location::FpuRegisterLocation(XMM0); |
| 1002 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1003 | |
| 1004 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 1008 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 1009 | } |
| 1010 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1011 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1012 | switch (type) { |
| 1013 | case Primitive::kPrimBoolean: |
| 1014 | case Primitive::kPrimByte: |
| 1015 | case Primitive::kPrimChar: |
| 1016 | case Primitive::kPrimShort: |
| 1017 | case Primitive::kPrimInt: |
| 1018 | case Primitive::kPrimNot: { |
| 1019 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1020 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1021 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1022 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1023 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1024 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1025 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1026 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1027 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1028 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1029 | uint32_t index = gp_index_; |
| 1030 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1031 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1032 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1033 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 1034 | calling_convention.GetRegisterPairAt(index)); |
| 1035 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1036 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1037 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1042 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1043 | stack_index_++; |
| 1044 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1045 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1046 | } else { |
| 1047 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1052 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1053 | stack_index_ += 2; |
| 1054 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 1055 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 1056 | } else { |
| 1057 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1061 | case Primitive::kPrimVoid: |
| 1062 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 1063 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1064 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1065 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1066 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1067 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1068 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 1069 | if (source.Equals(destination)) { |
| 1070 | return; |
| 1071 | } |
| 1072 | if (destination.IsRegister()) { |
| 1073 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1074 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1075 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1076 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1077 | } else { |
| 1078 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1079 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1080 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1081 | } else if (destination.IsFpuRegister()) { |
| 1082 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1083 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1084 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1085 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1086 | } else { |
| 1087 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1088 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1089 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1090 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1091 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1092 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1093 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1094 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1095 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1096 | } else if (source.IsConstant()) { |
| 1097 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1098 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1099 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1100 | } else { |
| 1101 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1102 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1103 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1109 | if (source.Equals(destination)) { |
| 1110 | return; |
| 1111 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1112 | if (destination.IsRegisterPair()) { |
| 1113 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1114 | EmitParallelMoves( |
| 1115 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1116 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1117 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1118 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1119 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1120 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1121 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1122 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1123 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1124 | __ psrlq(src_reg, Immediate(32)); |
| 1125 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1126 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1127 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1128 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1129 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1130 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1131 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1132 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1133 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1134 | if (source.IsFpuRegister()) { |
| 1135 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1136 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1137 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1138 | } else if (source.IsRegisterPair()) { |
| 1139 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1140 | // Create stack space for 2 elements. |
| 1141 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1142 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1143 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1144 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1145 | // And remove the temporary stack space we allocated. |
| 1146 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1147 | } else { |
| 1148 | LOG(FATAL) << "Unimplemented"; |
| 1149 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1150 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1151 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1152 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1153 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1154 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1155 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1156 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1157 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1158 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1159 | } else if (source.IsConstant()) { |
| 1160 | HConstant* constant = source.GetConstant(); |
| 1161 | int64_t value; |
| 1162 | if (constant->IsLongConstant()) { |
| 1163 | value = constant->AsLongConstant()->GetValue(); |
| 1164 | } else { |
| 1165 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1166 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1167 | } |
| 1168 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1169 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1170 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1171 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1172 | EmitParallelMoves( |
| 1173 | Location::StackSlot(source.GetStackIndex()), |
| 1174 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1175 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1176 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1177 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1178 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | } |
| 1182 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1183 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1184 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1185 | if (instruction->IsCurrentMethod()) { |
| 1186 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 1187 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1188 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1189 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1190 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1191 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 1192 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1193 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1194 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1195 | } else if (location.IsStackSlot()) { |
| 1196 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 1197 | } else { |
| 1198 | DCHECK(location.IsConstant()); |
| 1199 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 1200 | } |
| 1201 | } else if (const_to_move->IsLongConstant()) { |
| 1202 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 1203 | if (location.IsRegisterPair()) { |
| 1204 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 1205 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 1206 | } else if (location.IsDoubleStackSlot()) { |
| 1207 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1208 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 1209 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1210 | } else { |
| 1211 | DCHECK(location.IsConstant()); |
| 1212 | DCHECK_EQ(location.GetConstant(), instruction); |
| 1213 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1214 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 1215 | } else if (instruction->IsTemporary()) { |
| 1216 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 1217 | if (temp_location.IsStackSlot()) { |
| 1218 | Move32(location, temp_location); |
| 1219 | } else { |
| 1220 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 1221 | Move64(location, temp_location); |
| 1222 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 1223 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1224 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1225 | switch (instruction->GetType()) { |
| 1226 | case Primitive::kPrimBoolean: |
| 1227 | case Primitive::kPrimByte: |
| 1228 | case Primitive::kPrimChar: |
| 1229 | case Primitive::kPrimShort: |
| 1230 | case Primitive::kPrimInt: |
| 1231 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1232 | case Primitive::kPrimFloat: |
| 1233 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1234 | break; |
| 1235 | |
| 1236 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1237 | case Primitive::kPrimDouble: |
| 1238 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1239 | break; |
| 1240 | |
| 1241 | default: |
| 1242 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 1243 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1244 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1245 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1246 | switch (instruction->GetType()) { |
| 1247 | case Primitive::kPrimBoolean: |
| 1248 | case Primitive::kPrimByte: |
| 1249 | case Primitive::kPrimChar: |
| 1250 | case Primitive::kPrimShort: |
| 1251 | case Primitive::kPrimInt: |
| 1252 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1253 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1254 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1255 | break; |
| 1256 | |
| 1257 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1258 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 1259 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1260 | break; |
| 1261 | |
| 1262 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1263 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1264 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1268 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1269 | DCHECK(location.IsRegister()); |
| 1270 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1271 | } |
| 1272 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1273 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 1274 | if (Primitive::Is64BitType(dst_type)) { |
| 1275 | Move64(dst, src); |
| 1276 | } else { |
| 1277 | Move32(dst, src); |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1282 | if (location.IsRegister()) { |
| 1283 | locations->AddTemp(location); |
| 1284 | } else if (location.IsRegisterPair()) { |
| 1285 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1286 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1287 | } else { |
| 1288 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1289 | } |
| 1290 | } |
| 1291 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1292 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1293 | DCHECK(!successor->IsExitBlock()); |
| 1294 | |
| 1295 | HBasicBlock* block = got->GetBlock(); |
| 1296 | HInstruction* previous = got->GetPrevious(); |
| 1297 | |
| 1298 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1299 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1300 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1301 | return; |
| 1302 | } |
| 1303 | |
| 1304 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1305 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1306 | } |
| 1307 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1308 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1312 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1313 | got->SetLocations(nullptr); |
| 1314 | } |
| 1315 | |
| 1316 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1317 | HandleGoto(got, got->GetSuccessor()); |
| 1318 | } |
| 1319 | |
| 1320 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1321 | try_boundary->SetLocations(nullptr); |
| 1322 | } |
| 1323 | |
| 1324 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1325 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1326 | if (!successor->IsExitBlock()) { |
| 1327 | HandleGoto(try_boundary, successor); |
| 1328 | } |
| 1329 | } |
| 1330 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1331 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1332 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1335 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1338 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 1339 | Label* true_label, |
| 1340 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1341 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1342 | __ j(kUnordered, true_label); |
| 1343 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1344 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1345 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1346 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 1350 | Label* true_label, |
| 1351 | Label* false_label) { |
| 1352 | LocationSummary* locations = cond->GetLocations(); |
| 1353 | Location left = locations->InAt(0); |
| 1354 | Location right = locations->InAt(1); |
| 1355 | IfCondition if_cond = cond->GetCondition(); |
| 1356 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1357 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1358 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1359 | IfCondition true_high_cond = if_cond; |
| 1360 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1361 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1362 | |
| 1363 | // Set the conditions for the test, remembering that == needs to be |
| 1364 | // decided using the low words. |
| 1365 | switch (if_cond) { |
| 1366 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1367 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1368 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1369 | break; |
| 1370 | case kCondLT: |
| 1371 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1372 | break; |
| 1373 | case kCondLE: |
| 1374 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1375 | break; |
| 1376 | case kCondGT: |
| 1377 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1378 | break; |
| 1379 | case kCondGE: |
| 1380 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1381 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1382 | case kCondB: |
| 1383 | false_high_cond = kCondA; |
| 1384 | break; |
| 1385 | case kCondBE: |
| 1386 | true_high_cond = kCondB; |
| 1387 | break; |
| 1388 | case kCondA: |
| 1389 | false_high_cond = kCondB; |
| 1390 | break; |
| 1391 | case kCondAE: |
| 1392 | true_high_cond = kCondA; |
| 1393 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | if (right.IsConstant()) { |
| 1397 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1398 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1399 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1400 | |
| 1401 | if (val_high == 0) { |
| 1402 | __ testl(left_high, left_high); |
| 1403 | } else { |
| 1404 | __ cmpl(left_high, Immediate(val_high)); |
| 1405 | } |
| 1406 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1407 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1408 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1409 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1410 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1411 | __ j(X86Condition(true_high_cond), true_label); |
| 1412 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1413 | } |
| 1414 | // Must be equal high, so compare the lows. |
| 1415 | if (val_low == 0) { |
| 1416 | __ testl(left_low, left_low); |
| 1417 | } else { |
| 1418 | __ cmpl(left_low, Immediate(val_low)); |
| 1419 | } |
| 1420 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1421 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1422 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1423 | |
| 1424 | __ cmpl(left_high, right_high); |
| 1425 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1426 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1427 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1428 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1429 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1430 | __ j(X86Condition(true_high_cond), true_label); |
| 1431 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1432 | } |
| 1433 | // Must be equal high, so compare the lows. |
| 1434 | __ cmpl(left_low, right_low); |
| 1435 | } |
| 1436 | // The last comparison might be unsigned. |
| 1437 | __ j(final_condition, true_label); |
| 1438 | } |
| 1439 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1440 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
| 1441 | Label* true_target_in, |
| 1442 | Label* false_target_in) { |
| 1443 | // Generated branching requires both targets to be explicit. If either of the |
| 1444 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
| 1445 | Label fallthrough_target; |
| 1446 | Label* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1447 | Label* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
| 1448 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1449 | LocationSummary* locations = condition->GetLocations(); |
| 1450 | Location left = locations->InAt(0); |
| 1451 | Location right = locations->InAt(1); |
| 1452 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1453 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1454 | switch (type) { |
| 1455 | case Primitive::kPrimLong: |
| 1456 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1457 | break; |
| 1458 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1459 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1460 | GenerateFPJumps(condition, true_target, false_target); |
| 1461 | break; |
| 1462 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1463 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1464 | GenerateFPJumps(condition, true_target, false_target); |
| 1465 | break; |
| 1466 | default: |
| 1467 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1468 | } |
| 1469 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1470 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1471 | __ jmp(false_target); |
| 1472 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1473 | |
| 1474 | if (fallthrough_target.IsLinked()) { |
| 1475 | __ Bind(&fallthrough_target); |
| 1476 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1477 | } |
| 1478 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1479 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1480 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1481 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1482 | // conditions if they are materialized due to the complex branching. |
| 1483 | return cond->IsCondition() && |
| 1484 | cond->GetNext() == branch && |
| 1485 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1486 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1487 | } |
| 1488 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1489 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1490 | size_t condition_input_index, |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1491 | Label* true_target, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1492 | Label* false_target) { |
| 1493 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1494 | |
| 1495 | if (true_target == nullptr && false_target == nullptr) { |
| 1496 | // Nothing to do. The code always falls through. |
| 1497 | return; |
| 1498 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1499 | // Constant condition, statically compared against 1. |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1500 | if (cond->AsIntConstant()->IsOne()) { |
| 1501 | if (true_target != nullptr) { |
| 1502 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1503 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1504 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1505 | DCHECK(cond->AsIntConstant()->IsZero()); |
| 1506 | if (false_target != nullptr) { |
| 1507 | __ jmp(false_target); |
| 1508 | } |
| 1509 | } |
| 1510 | return; |
| 1511 | } |
| 1512 | |
| 1513 | // The following code generates these patterns: |
| 1514 | // (1) true_target == nullptr && false_target != nullptr |
| 1515 | // - opposite condition true => branch to false_target |
| 1516 | // (2) true_target != nullptr && false_target == nullptr |
| 1517 | // - condition true => branch to true_target |
| 1518 | // (3) true_target != nullptr && false_target != nullptr |
| 1519 | // - condition true => branch to true_target |
| 1520 | // - branch to false_target |
| 1521 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1522 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1523 | if (true_target == nullptr) { |
| 1524 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1525 | } else { |
| 1526 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1527 | } |
| 1528 | } else { |
| 1529 | // Materialized condition, compare against 0. |
| 1530 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1531 | if (lhs.IsRegister()) { |
| 1532 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1533 | } else { |
| 1534 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1535 | } |
| 1536 | if (true_target == nullptr) { |
| 1537 | __ j(kEqual, false_target); |
| 1538 | } else { |
| 1539 | __ j(kNotEqual, true_target); |
| 1540 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1541 | } |
| 1542 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1543 | // Condition has not been materialized, use its inputs as the comparison and |
| 1544 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1545 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1546 | |
| 1547 | // If this is a long or FP comparison that has been folded into |
| 1548 | // the HCondition, generate the comparison directly. |
| 1549 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1550 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1551 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1552 | return; |
| 1553 | } |
| 1554 | |
| 1555 | Location lhs = condition->GetLocations()->InAt(0); |
| 1556 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1557 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1558 | if (rhs.IsRegister()) { |
| 1559 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1560 | } else if (rhs.IsConstant()) { |
| 1561 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1562 | if (constant == 0) { |
| 1563 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1564 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1565 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1566 | } |
| 1567 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1568 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1569 | } |
| 1570 | if (true_target == nullptr) { |
| 1571 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1572 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1573 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1574 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1575 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1576 | |
| 1577 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1578 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1579 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1580 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1581 | } |
| 1582 | } |
| 1583 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1584 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1585 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1586 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1587 | locations->SetInAt(0, Location::Any()); |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1592 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1593 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1594 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1595 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1596 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1597 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1598 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1602 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1603 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1604 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1605 | locations->SetInAt(0, Location::Any()); |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1610 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1611 | DeoptimizationSlowPathX86(deoptimize); |
| 1612 | codegen_->AddSlowPath(slow_path); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1613 | GenerateTestAndBranch(deoptimize, |
| 1614 | /* condition_input_index */ 0, |
| 1615 | slow_path->GetEntryLabel(), |
| 1616 | /* false_target */ nullptr); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1619 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1620 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1621 | } |
| 1622 | |
| 1623 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1624 | codegen_->RecordPcInfo(info, info->GetDexPc()); |
| 1625 | } |
| 1626 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1627 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1628 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1629 | } |
| 1630 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1631 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1632 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1635 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1636 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1639 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1640 | // Nothing to do, this is driven by the code generator. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1643 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1644 | LocationSummary* locations = |
| 1645 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1646 | switch (store->InputAt(1)->GetType()) { |
| 1647 | case Primitive::kPrimBoolean: |
| 1648 | case Primitive::kPrimByte: |
| 1649 | case Primitive::kPrimChar: |
| 1650 | case Primitive::kPrimShort: |
| 1651 | case Primitive::kPrimInt: |
| 1652 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1653 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1654 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1655 | break; |
| 1656 | |
| 1657 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1658 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1659 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1660 | break; |
| 1661 | |
| 1662 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1663 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1664 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1667 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1668 | } |
| 1669 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1670 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1671 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1672 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1673 | // Handle the long/FP comparisons made in instruction simplification. |
| 1674 | switch (cond->InputAt(0)->GetType()) { |
| 1675 | case Primitive::kPrimLong: { |
| 1676 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1677 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1678 | if (cond->NeedsMaterialization()) { |
| 1679 | locations->SetOut(Location::RequiresRegister()); |
| 1680 | } |
| 1681 | break; |
| 1682 | } |
| 1683 | case Primitive::kPrimFloat: |
| 1684 | case Primitive::kPrimDouble: { |
| 1685 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1686 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1687 | if (cond->NeedsMaterialization()) { |
| 1688 | locations->SetOut(Location::RequiresRegister()); |
| 1689 | } |
| 1690 | break; |
| 1691 | } |
| 1692 | default: |
| 1693 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1694 | locations->SetInAt(1, Location::Any()); |
| 1695 | if (cond->NeedsMaterialization()) { |
| 1696 | // We need a byte register. |
| 1697 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1698 | } |
| 1699 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1700 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1701 | } |
| 1702 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1703 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1704 | if (!cond->NeedsMaterialization()) { |
| 1705 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1706 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1707 | |
| 1708 | LocationSummary* locations = cond->GetLocations(); |
| 1709 | Location lhs = locations->InAt(0); |
| 1710 | Location rhs = locations->InAt(1); |
| 1711 | Register reg = locations->Out().AsRegister<Register>(); |
| 1712 | Label true_label, false_label; |
| 1713 | |
| 1714 | switch (cond->InputAt(0)->GetType()) { |
| 1715 | default: { |
| 1716 | // Integer case. |
| 1717 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1718 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1719 | __ xorl(reg, reg); |
| 1720 | |
| 1721 | if (rhs.IsRegister()) { |
| 1722 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1723 | } else if (rhs.IsConstant()) { |
| 1724 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1725 | if (constant == 0) { |
| 1726 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1727 | } else { |
| 1728 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1729 | } |
| 1730 | } else { |
| 1731 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1732 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1733 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1734 | return; |
| 1735 | } |
| 1736 | case Primitive::kPrimLong: |
| 1737 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1738 | break; |
| 1739 | case Primitive::kPrimFloat: |
| 1740 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1741 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1742 | break; |
| 1743 | case Primitive::kPrimDouble: |
| 1744 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1745 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1746 | break; |
| 1747 | } |
| 1748 | |
| 1749 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1750 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1751 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1752 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1753 | __ Bind(&false_label); |
| 1754 | __ xorl(reg, reg); |
| 1755 | __ jmp(&done_label); |
| 1756 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1757 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1758 | __ Bind(&true_label); |
| 1759 | __ movl(reg, Immediate(1)); |
| 1760 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1764 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1768 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1772 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1776 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1780 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1784 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1788 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1792 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1796 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1800 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1804 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1808 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1811 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1812 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1816 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1820 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1824 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1828 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1832 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1836 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1840 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1843 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1844 | LocationSummary* locations = |
| 1845 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1846 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1849 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1850 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1853 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1854 | LocationSummary* locations = |
| 1855 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1856 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1857 | } |
| 1858 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1859 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1860 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1863 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1864 | LocationSummary* locations = |
| 1865 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1866 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1867 | } |
| 1868 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1869 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1870 | // Will be generated at use site. |
| 1871 | } |
| 1872 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1873 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1874 | LocationSummary* locations = |
| 1875 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1876 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1877 | } |
| 1878 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1879 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1880 | // Will be generated at use site. |
| 1881 | } |
| 1882 | |
| 1883 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1884 | LocationSummary* locations = |
| 1885 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1886 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1887 | } |
| 1888 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1889 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1890 | // Will be generated at use site. |
| 1891 | } |
| 1892 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1893 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1894 | memory_barrier->SetLocations(nullptr); |
| 1895 | } |
| 1896 | |
| 1897 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1898 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1899 | } |
| 1900 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1901 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1902 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1905 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1906 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1909 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1910 | LocationSummary* locations = |
| 1911 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1912 | switch (ret->InputAt(0)->GetType()) { |
| 1913 | case Primitive::kPrimBoolean: |
| 1914 | case Primitive::kPrimByte: |
| 1915 | case Primitive::kPrimChar: |
| 1916 | case Primitive::kPrimShort: |
| 1917 | case Primitive::kPrimInt: |
| 1918 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1919 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1920 | break; |
| 1921 | |
| 1922 | case Primitive::kPrimLong: |
| 1923 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1924 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1925 | break; |
| 1926 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1927 | case Primitive::kPrimFloat: |
| 1928 | case Primitive::kPrimDouble: |
| 1929 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1930 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1931 | break; |
| 1932 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1933 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1934 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1935 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1938 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1939 | if (kIsDebugBuild) { |
| 1940 | switch (ret->InputAt(0)->GetType()) { |
| 1941 | case Primitive::kPrimBoolean: |
| 1942 | case Primitive::kPrimByte: |
| 1943 | case Primitive::kPrimChar: |
| 1944 | case Primitive::kPrimShort: |
| 1945 | case Primitive::kPrimInt: |
| 1946 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1947 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1948 | break; |
| 1949 | |
| 1950 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1951 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1952 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1953 | break; |
| 1954 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1955 | case Primitive::kPrimFloat: |
| 1956 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1957 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1958 | break; |
| 1959 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1960 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1961 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1962 | } |
| 1963 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1964 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1965 | } |
| 1966 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1967 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1968 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1969 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1970 | // the method_idx. |
| 1971 | HandleInvoke(invoke); |
| 1972 | } |
| 1973 | |
| 1974 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1975 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1976 | } |
| 1977 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1978 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1979 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1980 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1981 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1982 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1983 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1984 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1985 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1986 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1987 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1988 | return; |
| 1989 | } |
| 1990 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1991 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1992 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1993 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1994 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1995 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1998 | if (codegen_->IsBaseline()) { |
| 1999 | // Baseline does not have enough registers if the current method also |
| 2000 | // needs a register. We therefore do not require a register for it, and let |
| 2001 | // the code generation of the invoke handle it. |
| 2002 | LocationSummary* locations = invoke->GetLocations(); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2003 | Location location = locations->InAt(invoke->GetSpecialInputIndex()); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2004 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2005 | locations->SetInAt(invoke->GetSpecialInputIndex(), Location::NoLocation()); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2006 | } |
| 2007 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2008 | } |
| 2009 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2010 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 2011 | if (invoke->GetLocations()->Intrinsified()) { |
| 2012 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 2013 | intrinsic.Dispatch(invoke); |
| 2014 | return true; |
| 2015 | } |
| 2016 | return false; |
| 2017 | } |
| 2018 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2019 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2020 | // When we do not run baseline, explicit clinit checks triggered by static |
| 2021 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 2022 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2023 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2024 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2025 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2026 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2027 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2028 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2029 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2030 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 2031 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2035 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 2036 | if (intrinsic.TryDispatch(invoke)) { |
| 2037 | return; |
| 2038 | } |
| 2039 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2040 | HandleInvoke(invoke); |
| 2041 | } |
| 2042 | |
| 2043 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2044 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2045 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2048 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2049 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 2050 | return; |
| 2051 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2052 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2053 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2054 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2055 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2058 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2059 | // This call to HandleInvoke allocates a temporary (core) register |
| 2060 | // which is also used to transfer the hidden argument from FP to |
| 2061 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2062 | HandleInvoke(invoke); |
| 2063 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2064 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2068 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2069 | LocationSummary* locations = invoke->GetLocations(); |
| 2070 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2071 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2072 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2073 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2074 | Location receiver = locations->InAt(0); |
| 2075 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2076 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2077 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2078 | // won't be modified thereafter, before the `call` instruction. |
| 2079 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2080 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2081 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2082 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2083 | if (receiver.IsStackSlot()) { |
| 2084 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2085 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2086 | __ movl(temp, Address(temp, class_offset)); |
| 2087 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2088 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2089 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2090 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2091 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2092 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2093 | // emit a read barrier for the previous class reference load. |
| 2094 | // However this is not required in practice, as this is an |
| 2095 | // intermediate/temporary reference and because the current |
| 2096 | // concurrent copying collector keeps the from-space memory |
| 2097 | // intact/accessible until the end of the marking phase (the |
| 2098 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2099 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2100 | // temp = temp->GetImtEntryAt(method_offset); |
| 2101 | __ movl(temp, Address(temp, method_offset)); |
| 2102 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2103 | __ call(Address(temp, |
| 2104 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2105 | |
| 2106 | DCHECK(!codegen_->IsLeafMethod()); |
| 2107 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2108 | } |
| 2109 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2110 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2111 | LocationSummary* locations = |
| 2112 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2113 | switch (neg->GetResultType()) { |
| 2114 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2115 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2116 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2117 | locations->SetOut(Location::SameAsFirstInput()); |
| 2118 | break; |
| 2119 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2120 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2121 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2122 | locations->SetOut(Location::SameAsFirstInput()); |
| 2123 | locations->AddTemp(Location::RequiresRegister()); |
| 2124 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2125 | break; |
| 2126 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2127 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2128 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2129 | locations->SetOut(Location::SameAsFirstInput()); |
| 2130 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2131 | break; |
| 2132 | |
| 2133 | default: |
| 2134 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2139 | LocationSummary* locations = neg->GetLocations(); |
| 2140 | Location out = locations->Out(); |
| 2141 | Location in = locations->InAt(0); |
| 2142 | switch (neg->GetResultType()) { |
| 2143 | case Primitive::kPrimInt: |
| 2144 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2145 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2146 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2147 | break; |
| 2148 | |
| 2149 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2150 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2151 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2152 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2153 | // Negation is similar to subtraction from zero. The least |
| 2154 | // significant byte triggers a borrow when it is different from |
| 2155 | // zero; to take it into account, add 1 to the most significant |
| 2156 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2157 | // operation. |
| 2158 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2159 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2160 | break; |
| 2161 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2162 | case Primitive::kPrimFloat: { |
| 2163 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2164 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2165 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2166 | // Implement float negation with an exclusive or with value |
| 2167 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2168 | // single-precision floating-point number). |
| 2169 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2170 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2171 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2172 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2173 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2174 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2175 | case Primitive::kPrimDouble: { |
| 2176 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2177 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2178 | // Implement double negation with an exclusive or with value |
| 2179 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2180 | // a double-precision floating-point number). |
| 2181 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2182 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2183 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2184 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2185 | |
| 2186 | default: |
| 2187 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2188 | } |
| 2189 | } |
| 2190 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2191 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2192 | Primitive::Type result_type = conversion->GetResultType(); |
| 2193 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2194 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2195 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2196 | // The float-to-long and double-to-long type conversions rely on a |
| 2197 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2198 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2199 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2200 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2201 | ? LocationSummary::kCall |
| 2202 | : LocationSummary::kNoCall; |
| 2203 | LocationSummary* locations = |
| 2204 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2205 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2206 | // The Java language does not allow treating boolean as an integral type but |
| 2207 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2208 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2209 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2210 | case Primitive::kPrimByte: |
| 2211 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2212 | case Primitive::kPrimBoolean: |
| 2213 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2214 | case Primitive::kPrimShort: |
| 2215 | case Primitive::kPrimInt: |
| 2216 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2217 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2218 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2219 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2220 | // the validation of the linear scan implementation |
| 2221 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2222 | break; |
| 2223 | |
| 2224 | default: |
| 2225 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2226 | << " to " << result_type; |
| 2227 | } |
| 2228 | break; |
| 2229 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2230 | case Primitive::kPrimShort: |
| 2231 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2232 | case Primitive::kPrimBoolean: |
| 2233 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2234 | case Primitive::kPrimByte: |
| 2235 | case Primitive::kPrimInt: |
| 2236 | case Primitive::kPrimChar: |
| 2237 | // Processing a Dex `int-to-short' instruction. |
| 2238 | locations->SetInAt(0, Location::Any()); |
| 2239 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2240 | break; |
| 2241 | |
| 2242 | default: |
| 2243 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2244 | << " to " << result_type; |
| 2245 | } |
| 2246 | break; |
| 2247 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2248 | case Primitive::kPrimInt: |
| 2249 | switch (input_type) { |
| 2250 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2251 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2252 | locations->SetInAt(0, Location::Any()); |
| 2253 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2254 | break; |
| 2255 | |
| 2256 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2257 | // Processing a Dex `float-to-int' instruction. |
| 2258 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2259 | locations->SetOut(Location::RequiresRegister()); |
| 2260 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2261 | break; |
| 2262 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2263 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2264 | // Processing a Dex `double-to-int' instruction. |
| 2265 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2266 | locations->SetOut(Location::RequiresRegister()); |
| 2267 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2268 | break; |
| 2269 | |
| 2270 | default: |
| 2271 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2272 | << " to " << result_type; |
| 2273 | } |
| 2274 | break; |
| 2275 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2276 | case Primitive::kPrimLong: |
| 2277 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2278 | case Primitive::kPrimBoolean: |
| 2279 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2280 | case Primitive::kPrimByte: |
| 2281 | case Primitive::kPrimShort: |
| 2282 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2283 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2284 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2285 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2286 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2287 | break; |
| 2288 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2289 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2290 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2291 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2292 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2293 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2294 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2295 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2296 | // The runtime helper puts the result in EAX, EDX. |
| 2297 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2298 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2299 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2300 | |
| 2301 | default: |
| 2302 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2303 | << " to " << result_type; |
| 2304 | } |
| 2305 | break; |
| 2306 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2307 | case Primitive::kPrimChar: |
| 2308 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2309 | case Primitive::kPrimBoolean: |
| 2310 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2311 | case Primitive::kPrimByte: |
| 2312 | case Primitive::kPrimShort: |
| 2313 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2314 | // Processing a Dex `int-to-char' instruction. |
| 2315 | locations->SetInAt(0, Location::Any()); |
| 2316 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2317 | break; |
| 2318 | |
| 2319 | default: |
| 2320 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2321 | << " to " << result_type; |
| 2322 | } |
| 2323 | break; |
| 2324 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2325 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2326 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2327 | case Primitive::kPrimBoolean: |
| 2328 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2329 | case Primitive::kPrimByte: |
| 2330 | case Primitive::kPrimShort: |
| 2331 | case Primitive::kPrimInt: |
| 2332 | case Primitive::kPrimChar: |
| 2333 | // Processing a Dex `int-to-float' instruction. |
| 2334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2335 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2336 | break; |
| 2337 | |
| 2338 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2339 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2340 | locations->SetInAt(0, Location::Any()); |
| 2341 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2342 | break; |
| 2343 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2344 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2345 | // Processing a Dex `double-to-float' instruction. |
| 2346 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2347 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2348 | break; |
| 2349 | |
| 2350 | default: |
| 2351 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2352 | << " to " << result_type; |
| 2353 | }; |
| 2354 | break; |
| 2355 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2356 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2357 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2358 | case Primitive::kPrimBoolean: |
| 2359 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2360 | case Primitive::kPrimByte: |
| 2361 | case Primitive::kPrimShort: |
| 2362 | case Primitive::kPrimInt: |
| 2363 | case Primitive::kPrimChar: |
| 2364 | // Processing a Dex `int-to-double' instruction. |
| 2365 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2366 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2367 | break; |
| 2368 | |
| 2369 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2370 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2371 | locations->SetInAt(0, Location::Any()); |
| 2372 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2373 | break; |
| 2374 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2375 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2376 | // Processing a Dex `float-to-double' instruction. |
| 2377 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2378 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2379 | break; |
| 2380 | |
| 2381 | default: |
| 2382 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2383 | << " to " << result_type; |
| 2384 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2385 | break; |
| 2386 | |
| 2387 | default: |
| 2388 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2389 | << " to " << result_type; |
| 2390 | } |
| 2391 | } |
| 2392 | |
| 2393 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2394 | LocationSummary* locations = conversion->GetLocations(); |
| 2395 | Location out = locations->Out(); |
| 2396 | Location in = locations->InAt(0); |
| 2397 | Primitive::Type result_type = conversion->GetResultType(); |
| 2398 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2399 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2400 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2401 | case Primitive::kPrimByte: |
| 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 | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2405 | case Primitive::kPrimShort: |
| 2406 | case Primitive::kPrimInt: |
| 2407 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2408 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2409 | if (in.IsRegister()) { |
| 2410 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2411 | } else { |
| 2412 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2413 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2414 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2415 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2416 | break; |
| 2417 | |
| 2418 | default: |
| 2419 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2420 | << " to " << result_type; |
| 2421 | } |
| 2422 | break; |
| 2423 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2424 | case Primitive::kPrimShort: |
| 2425 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2426 | case Primitive::kPrimBoolean: |
| 2427 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2428 | case Primitive::kPrimByte: |
| 2429 | case Primitive::kPrimInt: |
| 2430 | case Primitive::kPrimChar: |
| 2431 | // Processing a Dex `int-to-short' instruction. |
| 2432 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2433 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2434 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2435 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2436 | } else { |
| 2437 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2438 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2439 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2440 | } |
| 2441 | break; |
| 2442 | |
| 2443 | default: |
| 2444 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2445 | << " to " << result_type; |
| 2446 | } |
| 2447 | break; |
| 2448 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2449 | case Primitive::kPrimInt: |
| 2450 | switch (input_type) { |
| 2451 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2452 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2453 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2454 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2455 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2456 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2457 | } else { |
| 2458 | DCHECK(in.IsConstant()); |
| 2459 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2460 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2461 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2462 | } |
| 2463 | break; |
| 2464 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2465 | case Primitive::kPrimFloat: { |
| 2466 | // Processing a Dex `float-to-int' instruction. |
| 2467 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2468 | Register output = out.AsRegister<Register>(); |
| 2469 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2470 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2471 | |
| 2472 | __ movl(output, Immediate(kPrimIntMax)); |
| 2473 | // temp = int-to-float(output) |
| 2474 | __ cvtsi2ss(temp, output); |
| 2475 | // if input >= temp goto done |
| 2476 | __ comiss(input, temp); |
| 2477 | __ j(kAboveEqual, &done); |
| 2478 | // if input == NaN goto nan |
| 2479 | __ j(kUnordered, &nan); |
| 2480 | // output = float-to-int-truncate(input) |
| 2481 | __ cvttss2si(output, input); |
| 2482 | __ jmp(&done); |
| 2483 | __ Bind(&nan); |
| 2484 | // output = 0 |
| 2485 | __ xorl(output, output); |
| 2486 | __ Bind(&done); |
| 2487 | break; |
| 2488 | } |
| 2489 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2490 | case Primitive::kPrimDouble: { |
| 2491 | // Processing a Dex `double-to-int' instruction. |
| 2492 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2493 | Register output = out.AsRegister<Register>(); |
| 2494 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2495 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2496 | |
| 2497 | __ movl(output, Immediate(kPrimIntMax)); |
| 2498 | // temp = int-to-double(output) |
| 2499 | __ cvtsi2sd(temp, output); |
| 2500 | // if input >= temp goto done |
| 2501 | __ comisd(input, temp); |
| 2502 | __ j(kAboveEqual, &done); |
| 2503 | // if input == NaN goto nan |
| 2504 | __ j(kUnordered, &nan); |
| 2505 | // output = double-to-int-truncate(input) |
| 2506 | __ cvttsd2si(output, input); |
| 2507 | __ jmp(&done); |
| 2508 | __ Bind(&nan); |
| 2509 | // output = 0 |
| 2510 | __ xorl(output, output); |
| 2511 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2512 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2513 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2514 | |
| 2515 | default: |
| 2516 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2517 | << " to " << result_type; |
| 2518 | } |
| 2519 | break; |
| 2520 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2521 | case Primitive::kPrimLong: |
| 2522 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2523 | case Primitive::kPrimBoolean: |
| 2524 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2525 | case Primitive::kPrimByte: |
| 2526 | case Primitive::kPrimShort: |
| 2527 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2528 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2529 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2530 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2531 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2532 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2533 | __ cdq(); |
| 2534 | break; |
| 2535 | |
| 2536 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2537 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2538 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2539 | conversion, |
| 2540 | conversion->GetDexPc(), |
| 2541 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2542 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2543 | break; |
| 2544 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2545 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2546 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2547 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2548 | conversion, |
| 2549 | conversion->GetDexPc(), |
| 2550 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2551 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2552 | break; |
| 2553 | |
| 2554 | default: |
| 2555 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2556 | << " to " << result_type; |
| 2557 | } |
| 2558 | break; |
| 2559 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2560 | case Primitive::kPrimChar: |
| 2561 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2562 | case Primitive::kPrimBoolean: |
| 2563 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2564 | case Primitive::kPrimByte: |
| 2565 | case Primitive::kPrimShort: |
| 2566 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2567 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2568 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2569 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2570 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2571 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2572 | } else { |
| 2573 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2574 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2575 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2576 | } |
| 2577 | break; |
| 2578 | |
| 2579 | default: |
| 2580 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2581 | << " to " << result_type; |
| 2582 | } |
| 2583 | break; |
| 2584 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2585 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2586 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2587 | case Primitive::kPrimBoolean: |
| 2588 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2589 | case Primitive::kPrimByte: |
| 2590 | case Primitive::kPrimShort: |
| 2591 | case Primitive::kPrimInt: |
| 2592 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2593 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2594 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2595 | break; |
| 2596 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2597 | case Primitive::kPrimLong: { |
| 2598 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2599 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2600 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2601 | // Create stack space for the call to |
| 2602 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2603 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2604 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2605 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2606 | __ subl(ESP, Immediate(adjustment)); |
| 2607 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2608 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2609 | // Load the value to the FP stack, using temporaries if needed. |
| 2610 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2611 | |
| 2612 | if (out.IsStackSlot()) { |
| 2613 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2614 | } else { |
| 2615 | __ fstps(Address(ESP, 0)); |
| 2616 | Location stack_temp = Location::StackSlot(0); |
| 2617 | codegen_->Move32(out, stack_temp); |
| 2618 | } |
| 2619 | |
| 2620 | // Remove the temporary stack space we allocated. |
| 2621 | if (adjustment != 0) { |
| 2622 | __ addl(ESP, Immediate(adjustment)); |
| 2623 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2624 | break; |
| 2625 | } |
| 2626 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2627 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2628 | // Processing a Dex `double-to-float' instruction. |
| 2629 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2630 | break; |
| 2631 | |
| 2632 | default: |
| 2633 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2634 | << " to " << result_type; |
| 2635 | }; |
| 2636 | break; |
| 2637 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2638 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2639 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2640 | case Primitive::kPrimBoolean: |
| 2641 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2642 | case Primitive::kPrimByte: |
| 2643 | case Primitive::kPrimShort: |
| 2644 | case Primitive::kPrimInt: |
| 2645 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2646 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2647 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2648 | break; |
| 2649 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2650 | case Primitive::kPrimLong: { |
| 2651 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2652 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2653 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2654 | // Create stack space for the call to |
| 2655 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2656 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2657 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2658 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2659 | __ subl(ESP, Immediate(adjustment)); |
| 2660 | } |
| 2661 | |
| 2662 | // Load the value to the FP stack, using temporaries if needed. |
| 2663 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2664 | |
| 2665 | if (out.IsDoubleStackSlot()) { |
| 2666 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2667 | } else { |
| 2668 | __ fstpl(Address(ESP, 0)); |
| 2669 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2670 | codegen_->Move64(out, stack_temp); |
| 2671 | } |
| 2672 | |
| 2673 | // Remove the temporary stack space we allocated. |
| 2674 | if (adjustment != 0) { |
| 2675 | __ addl(ESP, Immediate(adjustment)); |
| 2676 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2677 | break; |
| 2678 | } |
| 2679 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2680 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2681 | // Processing a Dex `float-to-double' instruction. |
| 2682 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2683 | break; |
| 2684 | |
| 2685 | default: |
| 2686 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2687 | << " to " << result_type; |
| 2688 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2689 | break; |
| 2690 | |
| 2691 | default: |
| 2692 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2693 | << " to " << result_type; |
| 2694 | } |
| 2695 | } |
| 2696 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2697 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2698 | LocationSummary* locations = |
| 2699 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2700 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2701 | case Primitive::kPrimInt: { |
| 2702 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2703 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2704 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2705 | break; |
| 2706 | } |
| 2707 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2708 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2709 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2710 | locations->SetInAt(1, Location::Any()); |
| 2711 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2712 | break; |
| 2713 | } |
| 2714 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2715 | case Primitive::kPrimFloat: |
| 2716 | case Primitive::kPrimDouble: { |
| 2717 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2718 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2719 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2720 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2721 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2722 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2723 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2724 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2725 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2726 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2730 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2731 | Location first = locations->InAt(0); |
| 2732 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2733 | Location out = locations->Out(); |
| 2734 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2735 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2736 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2737 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2738 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2739 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2740 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2741 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2742 | } else { |
| 2743 | __ leal(out.AsRegister<Register>(), Address( |
| 2744 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2745 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2746 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2747 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2748 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2749 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2750 | } else { |
| 2751 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2752 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2753 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2754 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2755 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2756 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2757 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2761 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2762 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2763 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2764 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2765 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2766 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2767 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2768 | } else { |
| 2769 | DCHECK(second.IsConstant()) << second; |
| 2770 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2771 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2772 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2773 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2774 | break; |
| 2775 | } |
| 2776 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2777 | case Primitive::kPrimFloat: { |
| 2778 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2779 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2780 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2781 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2782 | DCHECK(!const_area->NeedsMaterialization()); |
| 2783 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2784 | codegen_->LiteralFloatAddress( |
| 2785 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2786 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2787 | } else { |
| 2788 | DCHECK(second.IsStackSlot()); |
| 2789 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2790 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2791 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | case Primitive::kPrimDouble: { |
| 2795 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2796 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2797 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2798 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2799 | DCHECK(!const_area->NeedsMaterialization()); |
| 2800 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2801 | codegen_->LiteralDoubleAddress( |
| 2802 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2803 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2804 | } else { |
| 2805 | DCHECK(second.IsDoubleStackSlot()); |
| 2806 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2807 | } |
| 2808 | break; |
| 2809 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2810 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2811 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2812 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2813 | } |
| 2814 | } |
| 2815 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2816 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2817 | LocationSummary* locations = |
| 2818 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2819 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2820 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2821 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2822 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2823 | locations->SetInAt(1, Location::Any()); |
| 2824 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2825 | break; |
| 2826 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2827 | case Primitive::kPrimFloat: |
| 2828 | case Primitive::kPrimDouble: { |
| 2829 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2830 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2831 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2832 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2833 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2834 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2835 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2836 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2837 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2841 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2842 | Location first = locations->InAt(0); |
| 2843 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2844 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2845 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2846 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2847 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2848 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2849 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2850 | __ subl(first.AsRegister<Register>(), |
| 2851 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2852 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2853 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2854 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2855 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2859 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2860 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2861 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2862 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2863 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2864 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2865 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2866 | } else { |
| 2867 | DCHECK(second.IsConstant()) << second; |
| 2868 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2869 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2870 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2871 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2872 | break; |
| 2873 | } |
| 2874 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2875 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2876 | if (second.IsFpuRegister()) { |
| 2877 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2878 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2879 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2880 | DCHECK(!const_area->NeedsMaterialization()); |
| 2881 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2882 | codegen_->LiteralFloatAddress( |
| 2883 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2884 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2885 | } else { |
| 2886 | DCHECK(second.IsStackSlot()); |
| 2887 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2888 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2889 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2893 | if (second.IsFpuRegister()) { |
| 2894 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2895 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2896 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2897 | DCHECK(!const_area->NeedsMaterialization()); |
| 2898 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2899 | codegen_->LiteralDoubleAddress( |
| 2900 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2901 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2902 | } else { |
| 2903 | DCHECK(second.IsDoubleStackSlot()); |
| 2904 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2905 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2906 | break; |
| 2907 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2908 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2909 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2910 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2914 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2915 | LocationSummary* locations = |
| 2916 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2917 | switch (mul->GetResultType()) { |
| 2918 | case Primitive::kPrimInt: |
| 2919 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2920 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2921 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2922 | // Can use 3 operand multiply. |
| 2923 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2924 | } else { |
| 2925 | locations->SetOut(Location::SameAsFirstInput()); |
| 2926 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2927 | break; |
| 2928 | case Primitive::kPrimLong: { |
| 2929 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2930 | locations->SetInAt(1, Location::Any()); |
| 2931 | locations->SetOut(Location::SameAsFirstInput()); |
| 2932 | // Needed for imul on 32bits with 64bits output. |
| 2933 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2934 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2935 | break; |
| 2936 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2937 | case Primitive::kPrimFloat: |
| 2938 | case Primitive::kPrimDouble: { |
| 2939 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2940 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2941 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2942 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2943 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2944 | |
| 2945 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2946 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2951 | LocationSummary* locations = mul->GetLocations(); |
| 2952 | Location first = locations->InAt(0); |
| 2953 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2954 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2955 | |
| 2956 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2957 | case Primitive::kPrimInt: |
| 2958 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2959 | // problems where the output may not be the same as the first operand. |
| 2960 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2961 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2962 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2963 | } else if (second.IsRegister()) { |
| 2964 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2965 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2966 | } else { |
| 2967 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2968 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2969 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2970 | } |
| 2971 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2972 | |
| 2973 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2974 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2975 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2976 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2977 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2978 | |
| 2979 | DCHECK_EQ(EAX, eax); |
| 2980 | DCHECK_EQ(EDX, edx); |
| 2981 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2982 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2983 | // output: in1 |
| 2984 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2985 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2986 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2987 | if (second.IsConstant()) { |
| 2988 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2989 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2990 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2991 | int32_t low_value = Low32Bits(value); |
| 2992 | int32_t high_value = High32Bits(value); |
| 2993 | Immediate low(low_value); |
| 2994 | Immediate high(high_value); |
| 2995 | |
| 2996 | __ movl(eax, high); |
| 2997 | // eax <- in1.lo * in2.hi |
| 2998 | __ imull(eax, in1_lo); |
| 2999 | // in1.hi <- in1.hi * in2.lo |
| 3000 | __ imull(in1_hi, low); |
| 3001 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3002 | __ addl(in1_hi, eax); |
| 3003 | // move in2_lo to eax to prepare for double precision |
| 3004 | __ movl(eax, low); |
| 3005 | // edx:eax <- in1.lo * in2.lo |
| 3006 | __ mull(in1_lo); |
| 3007 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3008 | __ addl(in1_hi, edx); |
| 3009 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3010 | __ movl(in1_lo, eax); |
| 3011 | } else if (second.IsRegisterPair()) { |
| 3012 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3013 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3014 | |
| 3015 | __ movl(eax, in2_hi); |
| 3016 | // eax <- in1.lo * in2.hi |
| 3017 | __ imull(eax, in1_lo); |
| 3018 | // in1.hi <- in1.hi * in2.lo |
| 3019 | __ imull(in1_hi, in2_lo); |
| 3020 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3021 | __ addl(in1_hi, eax); |
| 3022 | // move in1_lo to eax to prepare for double precision |
| 3023 | __ movl(eax, in1_lo); |
| 3024 | // edx:eax <- in1.lo * in2.lo |
| 3025 | __ mull(in2_lo); |
| 3026 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3027 | __ addl(in1_hi, edx); |
| 3028 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3029 | __ movl(in1_lo, eax); |
| 3030 | } else { |
| 3031 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3032 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3033 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3034 | |
| 3035 | __ movl(eax, in2_hi); |
| 3036 | // eax <- in1.lo * in2.hi |
| 3037 | __ imull(eax, in1_lo); |
| 3038 | // in1.hi <- in1.hi * in2.lo |
| 3039 | __ imull(in1_hi, in2_lo); |
| 3040 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3041 | __ addl(in1_hi, eax); |
| 3042 | // move in1_lo to eax to prepare for double precision |
| 3043 | __ movl(eax, in1_lo); |
| 3044 | // edx:eax <- in1.lo * in2.lo |
| 3045 | __ mull(in2_lo); |
| 3046 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3047 | __ addl(in1_hi, edx); |
| 3048 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3049 | __ movl(in1_lo, eax); |
| 3050 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3051 | |
| 3052 | break; |
| 3053 | } |
| 3054 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3055 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3056 | DCHECK(first.Equals(locations->Out())); |
| 3057 | if (second.IsFpuRegister()) { |
| 3058 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3059 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3060 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3061 | DCHECK(!const_area->NeedsMaterialization()); |
| 3062 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3063 | codegen_->LiteralFloatAddress( |
| 3064 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3065 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3066 | } else { |
| 3067 | DCHECK(second.IsStackSlot()); |
| 3068 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3069 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3070 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3074 | DCHECK(first.Equals(locations->Out())); |
| 3075 | if (second.IsFpuRegister()) { |
| 3076 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3077 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3078 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3079 | DCHECK(!const_area->NeedsMaterialization()); |
| 3080 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3081 | codegen_->LiteralDoubleAddress( |
| 3082 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3083 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3084 | } else { |
| 3085 | DCHECK(second.IsDoubleStackSlot()); |
| 3086 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3087 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3088 | break; |
| 3089 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3090 | |
| 3091 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3092 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3093 | } |
| 3094 | } |
| 3095 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3096 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3097 | uint32_t temp_offset, |
| 3098 | uint32_t stack_adjustment, |
| 3099 | bool is_fp, |
| 3100 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3101 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3102 | DCHECK(!is_wide); |
| 3103 | if (is_fp) { |
| 3104 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3105 | } else { |
| 3106 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3107 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3108 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3109 | DCHECK(is_wide); |
| 3110 | if (is_fp) { |
| 3111 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3112 | } else { |
| 3113 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3114 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3115 | } else { |
| 3116 | // 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] | 3117 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3118 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3119 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3120 | if (is_fp) { |
| 3121 | __ flds(Address(ESP, temp_offset)); |
| 3122 | } else { |
| 3123 | __ filds(Address(ESP, temp_offset)); |
| 3124 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3125 | } else { |
| 3126 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3127 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3128 | if (is_fp) { |
| 3129 | __ fldl(Address(ESP, temp_offset)); |
| 3130 | } else { |
| 3131 | __ fildl(Address(ESP, temp_offset)); |
| 3132 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3133 | } |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3138 | Primitive::Type type = rem->GetResultType(); |
| 3139 | bool is_float = type == Primitive::kPrimFloat; |
| 3140 | size_t elem_size = Primitive::ComponentSize(type); |
| 3141 | LocationSummary* locations = rem->GetLocations(); |
| 3142 | Location first = locations->InAt(0); |
| 3143 | Location second = locations->InAt(1); |
| 3144 | Location out = locations->Out(); |
| 3145 | |
| 3146 | // Create stack space for 2 elements. |
| 3147 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3148 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3149 | |
| 3150 | // 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] | 3151 | const bool is_wide = !is_float; |
| 3152 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3153 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3154 | |
| 3155 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3156 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3157 | __ Bind(&retry); |
| 3158 | __ fprem(); |
| 3159 | |
| 3160 | // Move FP status to AX. |
| 3161 | __ fstsw(); |
| 3162 | |
| 3163 | // And see if the argument reduction is complete. This is signaled by the |
| 3164 | // C2 FPU flag bit set to 0. |
| 3165 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3166 | __ j(kNotEqual, &retry); |
| 3167 | |
| 3168 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3169 | // Store FP top of stack to real stack. |
| 3170 | if (is_float) { |
| 3171 | __ fsts(Address(ESP, 0)); |
| 3172 | } else { |
| 3173 | __ fstl(Address(ESP, 0)); |
| 3174 | } |
| 3175 | |
| 3176 | // Pop the 2 items from the FP stack. |
| 3177 | __ fucompp(); |
| 3178 | |
| 3179 | // Load the value from the stack into an XMM register. |
| 3180 | DCHECK(out.IsFpuRegister()) << out; |
| 3181 | if (is_float) { |
| 3182 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3183 | } else { |
| 3184 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3185 | } |
| 3186 | |
| 3187 | // And remove the temporary stack space we allocated. |
| 3188 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3189 | } |
| 3190 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3191 | |
| 3192 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3193 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3194 | |
| 3195 | LocationSummary* locations = instruction->GetLocations(); |
| 3196 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3197 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3198 | |
| 3199 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3200 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3201 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3202 | |
| 3203 | DCHECK(imm == 1 || imm == -1); |
| 3204 | |
| 3205 | if (instruction->IsRem()) { |
| 3206 | __ xorl(out_register, out_register); |
| 3207 | } else { |
| 3208 | __ movl(out_register, input_register); |
| 3209 | if (imm == -1) { |
| 3210 | __ negl(out_register); |
| 3211 | } |
| 3212 | } |
| 3213 | } |
| 3214 | |
| 3215 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3216 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3217 | LocationSummary* locations = instruction->GetLocations(); |
| 3218 | |
| 3219 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3220 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3221 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame^] | 3222 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3223 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3224 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3225 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3226 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame^] | 3227 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3228 | __ testl(input_register, input_register); |
| 3229 | __ cmovl(kGreaterEqual, num, input_register); |
| 3230 | int shift = CTZ(imm); |
| 3231 | __ sarl(num, Immediate(shift)); |
| 3232 | |
| 3233 | if (imm < 0) { |
| 3234 | __ negl(num); |
| 3235 | } |
| 3236 | |
| 3237 | __ movl(out_register, num); |
| 3238 | } |
| 3239 | |
| 3240 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3241 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3242 | |
| 3243 | LocationSummary* locations = instruction->GetLocations(); |
| 3244 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3245 | |
| 3246 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3247 | Register out = locations->Out().AsRegister<Register>(); |
| 3248 | Register num; |
| 3249 | Register edx; |
| 3250 | |
| 3251 | if (instruction->IsDiv()) { |
| 3252 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3253 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3254 | } else { |
| 3255 | edx = locations->Out().AsRegister<Register>(); |
| 3256 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3257 | } |
| 3258 | |
| 3259 | DCHECK_EQ(EAX, eax); |
| 3260 | DCHECK_EQ(EDX, edx); |
| 3261 | if (instruction->IsDiv()) { |
| 3262 | DCHECK_EQ(EAX, out); |
| 3263 | } else { |
| 3264 | DCHECK_EQ(EDX, out); |
| 3265 | } |
| 3266 | |
| 3267 | int64_t magic; |
| 3268 | int shift; |
| 3269 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3270 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3271 | NearLabel ndiv; |
| 3272 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3273 | // If numerator is 0, the result is 0, no computation needed. |
| 3274 | __ testl(eax, eax); |
| 3275 | __ j(kNotEqual, &ndiv); |
| 3276 | |
| 3277 | __ xorl(out, out); |
| 3278 | __ jmp(&end); |
| 3279 | |
| 3280 | __ Bind(&ndiv); |
| 3281 | |
| 3282 | // Save the numerator. |
| 3283 | __ movl(num, eax); |
| 3284 | |
| 3285 | // EAX = magic |
| 3286 | __ movl(eax, Immediate(magic)); |
| 3287 | |
| 3288 | // EDX:EAX = magic * numerator |
| 3289 | __ imull(num); |
| 3290 | |
| 3291 | if (imm > 0 && magic < 0) { |
| 3292 | // EDX += num |
| 3293 | __ addl(edx, num); |
| 3294 | } else if (imm < 0 && magic > 0) { |
| 3295 | __ subl(edx, num); |
| 3296 | } |
| 3297 | |
| 3298 | // Shift if needed. |
| 3299 | if (shift != 0) { |
| 3300 | __ sarl(edx, Immediate(shift)); |
| 3301 | } |
| 3302 | |
| 3303 | // EDX += 1 if EDX < 0 |
| 3304 | __ movl(eax, edx); |
| 3305 | __ shrl(edx, Immediate(31)); |
| 3306 | __ addl(edx, eax); |
| 3307 | |
| 3308 | if (instruction->IsRem()) { |
| 3309 | __ movl(eax, num); |
| 3310 | __ imull(edx, Immediate(imm)); |
| 3311 | __ subl(eax, edx); |
| 3312 | __ movl(edx, eax); |
| 3313 | } else { |
| 3314 | __ movl(eax, edx); |
| 3315 | } |
| 3316 | __ Bind(&end); |
| 3317 | } |
| 3318 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3319 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3320 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3321 | |
| 3322 | LocationSummary* locations = instruction->GetLocations(); |
| 3323 | Location out = locations->Out(); |
| 3324 | Location first = locations->InAt(0); |
| 3325 | Location second = locations->InAt(1); |
| 3326 | bool is_div = instruction->IsDiv(); |
| 3327 | |
| 3328 | switch (instruction->GetResultType()) { |
| 3329 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3330 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3331 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3332 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3333 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3334 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3335 | |
| 3336 | if (imm == 0) { |
| 3337 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3338 | } else if (imm == 1 || imm == -1) { |
| 3339 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame^] | 3340 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3341 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3342 | } else { |
| 3343 | DCHECK(imm <= -2 || imm >= 2); |
| 3344 | GenerateDivRemWithAnyConstant(instruction); |
| 3345 | } |
| 3346 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3347 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3348 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3349 | is_div); |
| 3350 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3351 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3352 | Register second_reg = second.AsRegister<Register>(); |
| 3353 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3354 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3355 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3356 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3357 | __ cmpl(second_reg, Immediate(-1)); |
| 3358 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3359 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3360 | // edx:eax <- sign-extended of eax |
| 3361 | __ cdq(); |
| 3362 | // eax = quotient, edx = remainder |
| 3363 | __ idivl(second_reg); |
| 3364 | __ Bind(slow_path->GetExitLabel()); |
| 3365 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3366 | break; |
| 3367 | } |
| 3368 | |
| 3369 | case Primitive::kPrimLong: { |
| 3370 | InvokeRuntimeCallingConvention calling_convention; |
| 3371 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3372 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3373 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3374 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3375 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3376 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3377 | |
| 3378 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3379 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3380 | instruction, |
| 3381 | instruction->GetDexPc(), |
| 3382 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3383 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3384 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3385 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3386 | instruction, |
| 3387 | instruction->GetDexPc(), |
| 3388 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3389 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3390 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3391 | break; |
| 3392 | } |
| 3393 | |
| 3394 | default: |
| 3395 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3396 | } |
| 3397 | } |
| 3398 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3399 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3400 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3401 | ? LocationSummary::kCall |
| 3402 | : LocationSummary::kNoCall; |
| 3403 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3404 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3405 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3406 | case Primitive::kPrimInt: { |
| 3407 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3408 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3409 | locations->SetOut(Location::SameAsFirstInput()); |
| 3410 | // Intel uses edx:eax as the dividend. |
| 3411 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3412 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3413 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3414 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3415 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3416 | locations->AddTemp(Location::RequiresRegister()); |
| 3417 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3418 | break; |
| 3419 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3420 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3421 | InvokeRuntimeCallingConvention calling_convention; |
| 3422 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3423 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3424 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3425 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3426 | // Runtime helper puts the result in EAX, EDX. |
| 3427 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3428 | break; |
| 3429 | } |
| 3430 | case Primitive::kPrimFloat: |
| 3431 | case Primitive::kPrimDouble: { |
| 3432 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3433 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3434 | locations->SetOut(Location::SameAsFirstInput()); |
| 3435 | break; |
| 3436 | } |
| 3437 | |
| 3438 | default: |
| 3439 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3444 | LocationSummary* locations = div->GetLocations(); |
| 3445 | Location first = locations->InAt(0); |
| 3446 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3447 | |
| 3448 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3449 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3450 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3451 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3452 | break; |
| 3453 | } |
| 3454 | |
| 3455 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3456 | if (second.IsFpuRegister()) { |
| 3457 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3458 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3459 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3460 | DCHECK(!const_area->NeedsMaterialization()); |
| 3461 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3462 | codegen_->LiteralFloatAddress( |
| 3463 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3464 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3465 | } else { |
| 3466 | DCHECK(second.IsStackSlot()); |
| 3467 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3468 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3469 | break; |
| 3470 | } |
| 3471 | |
| 3472 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3473 | if (second.IsFpuRegister()) { |
| 3474 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3475 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3476 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3477 | DCHECK(!const_area->NeedsMaterialization()); |
| 3478 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3479 | codegen_->LiteralDoubleAddress( |
| 3480 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3481 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3482 | } else { |
| 3483 | DCHECK(second.IsDoubleStackSlot()); |
| 3484 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3485 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3486 | break; |
| 3487 | } |
| 3488 | |
| 3489 | default: |
| 3490 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3491 | } |
| 3492 | } |
| 3493 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3494 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3495 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3496 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3497 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3498 | ? LocationSummary::kCall |
| 3499 | : LocationSummary::kNoCall; |
| 3500 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3501 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3502 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3503 | case Primitive::kPrimInt: { |
| 3504 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3505 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3506 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3507 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3508 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3509 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3510 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3511 | locations->AddTemp(Location::RequiresRegister()); |
| 3512 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3513 | break; |
| 3514 | } |
| 3515 | case Primitive::kPrimLong: { |
| 3516 | InvokeRuntimeCallingConvention calling_convention; |
| 3517 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3518 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3519 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3520 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3521 | // Runtime helper puts the result in EAX, EDX. |
| 3522 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3523 | break; |
| 3524 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3525 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3526 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3527 | locations->SetInAt(0, Location::Any()); |
| 3528 | locations->SetInAt(1, Location::Any()); |
| 3529 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3530 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3531 | break; |
| 3532 | } |
| 3533 | |
| 3534 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3535 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3536 | } |
| 3537 | } |
| 3538 | |
| 3539 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3540 | Primitive::Type type = rem->GetResultType(); |
| 3541 | switch (type) { |
| 3542 | case Primitive::kPrimInt: |
| 3543 | case Primitive::kPrimLong: { |
| 3544 | GenerateDivRemIntegral(rem); |
| 3545 | break; |
| 3546 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3547 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3548 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3549 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3550 | break; |
| 3551 | } |
| 3552 | default: |
| 3553 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3554 | } |
| 3555 | } |
| 3556 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3557 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3558 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3559 | ? LocationSummary::kCallOnSlowPath |
| 3560 | : LocationSummary::kNoCall; |
| 3561 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3562 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3563 | case Primitive::kPrimByte: |
| 3564 | case Primitive::kPrimChar: |
| 3565 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3566 | case Primitive::kPrimInt: { |
| 3567 | locations->SetInAt(0, Location::Any()); |
| 3568 | break; |
| 3569 | } |
| 3570 | case Primitive::kPrimLong: { |
| 3571 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3572 | if (!instruction->IsConstant()) { |
| 3573 | locations->AddTemp(Location::RequiresRegister()); |
| 3574 | } |
| 3575 | break; |
| 3576 | } |
| 3577 | default: |
| 3578 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3579 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3580 | if (instruction->HasUses()) { |
| 3581 | locations->SetOut(Location::SameAsFirstInput()); |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3586 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3587 | codegen_->AddSlowPath(slow_path); |
| 3588 | |
| 3589 | LocationSummary* locations = instruction->GetLocations(); |
| 3590 | Location value = locations->InAt(0); |
| 3591 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3592 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3593 | case Primitive::kPrimByte: |
| 3594 | case Primitive::kPrimChar: |
| 3595 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3596 | case Primitive::kPrimInt: { |
| 3597 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3598 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3599 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3600 | } else if (value.IsStackSlot()) { |
| 3601 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3602 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3603 | } else { |
| 3604 | DCHECK(value.IsConstant()) << value; |
| 3605 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3606 | __ jmp(slow_path->GetEntryLabel()); |
| 3607 | } |
| 3608 | } |
| 3609 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3610 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3611 | case Primitive::kPrimLong: { |
| 3612 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3613 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3614 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3615 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3616 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3617 | } else { |
| 3618 | DCHECK(value.IsConstant()) << value; |
| 3619 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3620 | __ jmp(slow_path->GetEntryLabel()); |
| 3621 | } |
| 3622 | } |
| 3623 | break; |
| 3624 | } |
| 3625 | default: |
| 3626 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3627 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3628 | } |
| 3629 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3630 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3631 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3632 | |
| 3633 | LocationSummary* locations = |
| 3634 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3635 | |
| 3636 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3637 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3638 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3639 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3640 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3641 | // The shift count needs to be in CL or a constant. |
| 3642 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3643 | locations->SetOut(Location::SameAsFirstInput()); |
| 3644 | break; |
| 3645 | } |
| 3646 | default: |
| 3647 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3648 | } |
| 3649 | } |
| 3650 | |
| 3651 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3652 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3653 | |
| 3654 | LocationSummary* locations = op->GetLocations(); |
| 3655 | Location first = locations->InAt(0); |
| 3656 | Location second = locations->InAt(1); |
| 3657 | DCHECK(first.Equals(locations->Out())); |
| 3658 | |
| 3659 | switch (op->GetResultType()) { |
| 3660 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3661 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3662 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3663 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3664 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3665 | DCHECK_EQ(ECX, second_reg); |
| 3666 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3667 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3668 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3669 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3670 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3671 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3672 | } |
| 3673 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3674 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3675 | if (shift == 0) { |
| 3676 | return; |
| 3677 | } |
| 3678 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3679 | if (op->IsShl()) { |
| 3680 | __ shll(first_reg, imm); |
| 3681 | } else if (op->IsShr()) { |
| 3682 | __ sarl(first_reg, imm); |
| 3683 | } else { |
| 3684 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3685 | } |
| 3686 | } |
| 3687 | break; |
| 3688 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3689 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3690 | if (second.IsRegister()) { |
| 3691 | Register second_reg = second.AsRegister<Register>(); |
| 3692 | DCHECK_EQ(ECX, second_reg); |
| 3693 | if (op->IsShl()) { |
| 3694 | GenerateShlLong(first, second_reg); |
| 3695 | } else if (op->IsShr()) { |
| 3696 | GenerateShrLong(first, second_reg); |
| 3697 | } else { |
| 3698 | GenerateUShrLong(first, second_reg); |
| 3699 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3700 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3701 | // Shift by a constant. |
| 3702 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3703 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3704 | if (shift != 0) { |
| 3705 | if (op->IsShl()) { |
| 3706 | GenerateShlLong(first, shift); |
| 3707 | } else if (op->IsShr()) { |
| 3708 | GenerateShrLong(first, shift); |
| 3709 | } else { |
| 3710 | GenerateUShrLong(first, shift); |
| 3711 | } |
| 3712 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3713 | } |
| 3714 | break; |
| 3715 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3716 | default: |
| 3717 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3718 | } |
| 3719 | } |
| 3720 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3721 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3722 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3723 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3724 | if (shift == 1) { |
| 3725 | // This is just an addition. |
| 3726 | __ addl(low, low); |
| 3727 | __ adcl(high, high); |
| 3728 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3729 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3730 | codegen_->EmitParallelMoves( |
| 3731 | loc.ToLow(), |
| 3732 | loc.ToHigh(), |
| 3733 | Primitive::kPrimInt, |
| 3734 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3735 | loc.ToLow(), |
| 3736 | Primitive::kPrimInt); |
| 3737 | } else if (shift > 32) { |
| 3738 | // Low part becomes 0. High part is low part << (shift-32). |
| 3739 | __ movl(high, low); |
| 3740 | __ shll(high, Immediate(shift - 32)); |
| 3741 | __ xorl(low, low); |
| 3742 | } else { |
| 3743 | // Between 1 and 31. |
| 3744 | __ shld(high, low, Immediate(shift)); |
| 3745 | __ shll(low, Immediate(shift)); |
| 3746 | } |
| 3747 | } |
| 3748 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3749 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3750 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3751 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3752 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3753 | __ testl(shifter, Immediate(32)); |
| 3754 | __ j(kEqual, &done); |
| 3755 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3756 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3757 | __ Bind(&done); |
| 3758 | } |
| 3759 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3760 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3761 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3762 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3763 | if (shift == 32) { |
| 3764 | // Need to copy the sign. |
| 3765 | DCHECK_NE(low, high); |
| 3766 | __ movl(low, high); |
| 3767 | __ sarl(high, Immediate(31)); |
| 3768 | } else if (shift > 32) { |
| 3769 | DCHECK_NE(low, high); |
| 3770 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3771 | __ movl(low, high); |
| 3772 | __ sarl(high, Immediate(31)); |
| 3773 | __ sarl(low, Immediate(shift - 32)); |
| 3774 | } else { |
| 3775 | // Between 1 and 31. |
| 3776 | __ shrd(low, high, Immediate(shift)); |
| 3777 | __ sarl(high, Immediate(shift)); |
| 3778 | } |
| 3779 | } |
| 3780 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3781 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3782 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3783 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3784 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3785 | __ testl(shifter, Immediate(32)); |
| 3786 | __ j(kEqual, &done); |
| 3787 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3788 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3789 | __ Bind(&done); |
| 3790 | } |
| 3791 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3792 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3793 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3794 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3795 | if (shift == 32) { |
| 3796 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3797 | codegen_->EmitParallelMoves( |
| 3798 | loc.ToHigh(), |
| 3799 | loc.ToLow(), |
| 3800 | Primitive::kPrimInt, |
| 3801 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3802 | loc.ToHigh(), |
| 3803 | Primitive::kPrimInt); |
| 3804 | } else if (shift > 32) { |
| 3805 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3806 | __ movl(low, high); |
| 3807 | __ shrl(low, Immediate(shift - 32)); |
| 3808 | __ xorl(high, high); |
| 3809 | } else { |
| 3810 | // Between 1 and 31. |
| 3811 | __ shrd(low, high, Immediate(shift)); |
| 3812 | __ shrl(high, Immediate(shift)); |
| 3813 | } |
| 3814 | } |
| 3815 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3816 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3817 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3818 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3819 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3820 | __ testl(shifter, Immediate(32)); |
| 3821 | __ j(kEqual, &done); |
| 3822 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3823 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3824 | __ Bind(&done); |
| 3825 | } |
| 3826 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3827 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3828 | LocationSummary* locations = |
| 3829 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3830 | |
| 3831 | switch (ror->GetResultType()) { |
| 3832 | case Primitive::kPrimLong: |
| 3833 | // Add the temporary needed. |
| 3834 | locations->AddTemp(Location::RequiresRegister()); |
| 3835 | FALLTHROUGH_INTENDED; |
| 3836 | case Primitive::kPrimInt: |
| 3837 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3838 | // The shift count needs to be in CL (unless it is a constant). |
| 3839 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3840 | locations->SetOut(Location::SameAsFirstInput()); |
| 3841 | break; |
| 3842 | default: |
| 3843 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3844 | UNREACHABLE(); |
| 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3849 | LocationSummary* locations = ror->GetLocations(); |
| 3850 | Location first = locations->InAt(0); |
| 3851 | Location second = locations->InAt(1); |
| 3852 | |
| 3853 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3854 | Register first_reg = first.AsRegister<Register>(); |
| 3855 | if (second.IsRegister()) { |
| 3856 | Register second_reg = second.AsRegister<Register>(); |
| 3857 | __ rorl(first_reg, second_reg); |
| 3858 | } else { |
| 3859 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue); |
| 3860 | __ rorl(first_reg, imm); |
| 3861 | } |
| 3862 | return; |
| 3863 | } |
| 3864 | |
| 3865 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3866 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3867 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3868 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3869 | if (second.IsRegister()) { |
| 3870 | Register second_reg = second.AsRegister<Register>(); |
| 3871 | DCHECK_EQ(second_reg, ECX); |
| 3872 | __ movl(temp_reg, first_reg_hi); |
| 3873 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3874 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3875 | __ movl(temp_reg, first_reg_hi); |
| 3876 | __ testl(second_reg, Immediate(32)); |
| 3877 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3878 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3879 | } else { |
| 3880 | int32_t shift_amt = |
| 3881 | CodeGenerator::GetInt64ValueOf(second.GetConstant()) & kMaxLongShiftValue; |
| 3882 | if (shift_amt == 0) { |
| 3883 | // Already fine. |
| 3884 | return; |
| 3885 | } |
| 3886 | if (shift_amt == 32) { |
| 3887 | // Just swap. |
| 3888 | __ movl(temp_reg, first_reg_lo); |
| 3889 | __ movl(first_reg_lo, first_reg_hi); |
| 3890 | __ movl(first_reg_hi, temp_reg); |
| 3891 | return; |
| 3892 | } |
| 3893 | |
| 3894 | Immediate imm(shift_amt); |
| 3895 | // Save the constents of the low value. |
| 3896 | __ movl(temp_reg, first_reg_lo); |
| 3897 | |
| 3898 | // Shift right into low, feeding bits from high. |
| 3899 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3900 | |
| 3901 | // Shift right into high, feeding bits from the original low. |
| 3902 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3903 | |
| 3904 | // Swap if needed. |
| 3905 | if (shift_amt > 32) { |
| 3906 | __ movl(temp_reg, first_reg_lo); |
| 3907 | __ movl(first_reg_lo, first_reg_hi); |
| 3908 | __ movl(first_reg_hi, temp_reg); |
| 3909 | } |
| 3910 | } |
| 3911 | } |
| 3912 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3913 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3914 | HandleShift(shl); |
| 3915 | } |
| 3916 | |
| 3917 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3918 | HandleShift(shl); |
| 3919 | } |
| 3920 | |
| 3921 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3922 | HandleShift(shr); |
| 3923 | } |
| 3924 | |
| 3925 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3926 | HandleShift(shr); |
| 3927 | } |
| 3928 | |
| 3929 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3930 | HandleShift(ushr); |
| 3931 | } |
| 3932 | |
| 3933 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3934 | HandleShift(ushr); |
| 3935 | } |
| 3936 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3937 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3938 | LocationSummary* locations = |
| 3939 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3940 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3941 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3942 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3943 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3947 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3948 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3949 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3950 | instruction, |
| 3951 | instruction->GetDexPc(), |
| 3952 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3953 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3954 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3955 | } |
| 3956 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3957 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3958 | LocationSummary* locations = |
| 3959 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3960 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3961 | InvokeRuntimeCallingConvention calling_convention; |
| 3962 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3963 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3964 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3968 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3969 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3970 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3971 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3972 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3973 | instruction, |
| 3974 | instruction->GetDexPc(), |
| 3975 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3976 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3977 | DCHECK(!codegen_->IsLeafMethod()); |
| 3978 | } |
| 3979 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3980 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3981 | LocationSummary* locations = |
| 3982 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3983 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3984 | if (location.IsStackSlot()) { |
| 3985 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3986 | } else if (location.IsDoubleStackSlot()) { |
| 3987 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3988 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3989 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3990 | } |
| 3991 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3992 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3993 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3994 | } |
| 3995 | |
| 3996 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3997 | LocationSummary* locations = |
| 3998 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3999 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4000 | } |
| 4001 | |
| 4002 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4003 | } |
| 4004 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4005 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4006 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4007 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4008 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4009 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4010 | } |
| 4011 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4012 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4013 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4014 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4015 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4016 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4017 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4018 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4019 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4020 | break; |
| 4021 | |
| 4022 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4023 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4024 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4025 | break; |
| 4026 | |
| 4027 | default: |
| 4028 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4029 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4030 | } |
| 4031 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4032 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4033 | LocationSummary* locations = |
| 4034 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4036 | locations->SetOut(Location::SameAsFirstInput()); |
| 4037 | } |
| 4038 | |
| 4039 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4040 | LocationSummary* locations = bool_not->GetLocations(); |
| 4041 | Location in = locations->InAt(0); |
| 4042 | Location out = locations->Out(); |
| 4043 | DCHECK(in.Equals(out)); |
| 4044 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4045 | } |
| 4046 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4047 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4048 | LocationSummary* locations = |
| 4049 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4050 | switch (compare->InputAt(0)->GetType()) { |
| 4051 | case Primitive::kPrimLong: { |
| 4052 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4053 | locations->SetInAt(1, Location::Any()); |
| 4054 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4055 | break; |
| 4056 | } |
| 4057 | case Primitive::kPrimFloat: |
| 4058 | case Primitive::kPrimDouble: { |
| 4059 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 4060 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4061 | locations->SetOut(Location::RequiresRegister()); |
| 4062 | break; |
| 4063 | } |
| 4064 | default: |
| 4065 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4066 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4067 | } |
| 4068 | |
| 4069 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4070 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4071 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4072 | Location left = locations->InAt(0); |
| 4073 | Location right = locations->InAt(1); |
| 4074 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4075 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4076 | switch (compare->InputAt(0)->GetType()) { |
| 4077 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4078 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4079 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4080 | int32_t val_low = 0; |
| 4081 | int32_t val_high = 0; |
| 4082 | bool right_is_const = false; |
| 4083 | |
| 4084 | if (right.IsConstant()) { |
| 4085 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4086 | right_is_const = true; |
| 4087 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4088 | val_low = Low32Bits(val); |
| 4089 | val_high = High32Bits(val); |
| 4090 | } |
| 4091 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4092 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4093 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4094 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4095 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4096 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4097 | DCHECK(right_is_const) << right; |
| 4098 | if (val_high == 0) { |
| 4099 | __ testl(left_high, left_high); |
| 4100 | } else { |
| 4101 | __ cmpl(left_high, Immediate(val_high)); |
| 4102 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4103 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4104 | __ j(kLess, &less); // Signed compare. |
| 4105 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4106 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4107 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4108 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4109 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4110 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4111 | DCHECK(right_is_const) << right; |
| 4112 | if (val_low == 0) { |
| 4113 | __ testl(left_low, left_low); |
| 4114 | } else { |
| 4115 | __ cmpl(left_low, Immediate(val_low)); |
| 4116 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4117 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4118 | break; |
| 4119 | } |
| 4120 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4121 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4122 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 4123 | break; |
| 4124 | } |
| 4125 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4126 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4127 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4128 | break; |
| 4129 | } |
| 4130 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4131 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4132 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4133 | __ movl(out, Immediate(0)); |
| 4134 | __ j(kEqual, &done); |
| 4135 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 4136 | |
| 4137 | __ Bind(&greater); |
| 4138 | __ movl(out, Immediate(1)); |
| 4139 | __ jmp(&done); |
| 4140 | |
| 4141 | __ Bind(&less); |
| 4142 | __ movl(out, Immediate(-1)); |
| 4143 | |
| 4144 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4145 | } |
| 4146 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4147 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4148 | LocationSummary* locations = |
| 4149 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4150 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4151 | locations->SetInAt(i, Location::Any()); |
| 4152 | } |
| 4153 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4154 | } |
| 4155 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4156 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4157 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4158 | } |
| 4159 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4160 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4161 | /* |
| 4162 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4163 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4164 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4165 | */ |
| 4166 | switch (kind) { |
| 4167 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4168 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4169 | break; |
| 4170 | } |
| 4171 | case MemBarrierKind::kAnyStore: |
| 4172 | case MemBarrierKind::kLoadAny: |
| 4173 | case MemBarrierKind::kStoreStore: { |
| 4174 | // nop |
| 4175 | break; |
| 4176 | } |
| 4177 | default: |
| 4178 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4179 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4180 | } |
| 4181 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4182 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4183 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4184 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4185 | switch (desired_dispatch_info.code_ptr_location) { |
| 4186 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4187 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4188 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4189 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4190 | return HInvokeStaticOrDirect::DispatchInfo { |
| 4191 | desired_dispatch_info.method_load_kind, |
| 4192 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
| 4193 | desired_dispatch_info.method_load_data, |
| 4194 | 0u |
| 4195 | }; |
| 4196 | default: |
| 4197 | return desired_dispatch_info; |
| 4198 | } |
| 4199 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4200 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4201 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4202 | Register temp) { |
| 4203 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4204 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4205 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4206 | return location.AsRegister<Register>(); |
| 4207 | } |
| 4208 | // For intrinsics we allow any location, so it may be on the stack. |
| 4209 | if (!location.IsRegister()) { |
| 4210 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4211 | return temp; |
| 4212 | } |
| 4213 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4214 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4215 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4216 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4217 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
| 4218 | DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path. |
| 4219 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4220 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4221 | __ movl(temp, Address(ESP, stack_offset)); |
| 4222 | return temp; |
| 4223 | } |
| 4224 | return location.AsRegister<Register>(); |
| 4225 | } |
| 4226 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4227 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4228 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4229 | switch (invoke->GetMethodLoadKind()) { |
| 4230 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4231 | // temp = thread->string_init_entrypoint |
| 4232 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4233 | break; |
| 4234 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4235 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4236 | break; |
| 4237 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4238 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4239 | break; |
| 4240 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 4241 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 4242 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4243 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4244 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4245 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4246 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4247 | temp.AsRegister<Register>()); |
| 4248 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4249 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
| 4250 | // Add the patch entry and bind its label at the end of the instruction. |
| 4251 | pc_relative_dex_cache_patches_.emplace_back(*invoke->GetTargetMethod().dex_file, offset); |
| 4252 | __ Bind(&pc_relative_dex_cache_patches_.back().label); |
| 4253 | break; |
| 4254 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4255 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4256 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4257 | Register method_reg; |
| 4258 | Register reg = temp.AsRegister<Register>(); |
| 4259 | if (current_method.IsRegister()) { |
| 4260 | method_reg = current_method.AsRegister<Register>(); |
| 4261 | } else { |
| 4262 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 4263 | DCHECK(!current_method.IsValid()); |
| 4264 | method_reg = reg; |
| 4265 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4266 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4267 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4268 | __ movl(reg, Address(method_reg, |
| 4269 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4270 | // temp = temp[index_in_cache] |
| 4271 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 4272 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4273 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4274 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
| 4277 | switch (invoke->GetCodePtrLocation()) { |
| 4278 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4279 | __ call(GetFrameEntryLabel()); |
| 4280 | break; |
| 4281 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4282 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4283 | Label* label = &relative_call_patches_.back().label; |
| 4284 | __ call(label); // Bind to the patch label, override at link time. |
| 4285 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4286 | break; |
| 4287 | } |
| 4288 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4289 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4290 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4291 | LOG(FATAL) << "Unsupported"; |
| 4292 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4293 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4294 | // (callee_method + offset_of_quick_compiled_code)() |
| 4295 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4296 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4297 | kX86WordSize).Int32Value())); |
| 4298 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4302 | } |
| 4303 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4304 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4305 | Register temp = temp_in.AsRegister<Register>(); |
| 4306 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4307 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4308 | |
| 4309 | // Use the calling convention instead of the location of the receiver, as |
| 4310 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4311 | // slow path, the arguments have been moved to the right place, so here we are |
| 4312 | // guaranteed that the receiver is the first register of the calling convention. |
| 4313 | InvokeDexCallingConvention calling_convention; |
| 4314 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4315 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4316 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4317 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4318 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4319 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4320 | // emit a read barrier for the previous class reference load. |
| 4321 | // However this is not required in practice, as this is an |
| 4322 | // intermediate/temporary reference and because the current |
| 4323 | // concurrent copying collector keeps the from-space memory |
| 4324 | // intact/accessible until the end of the marking phase (the |
| 4325 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4326 | __ MaybeUnpoisonHeapReference(temp); |
| 4327 | // temp = temp->GetMethodAt(method_offset); |
| 4328 | __ movl(temp, Address(temp, method_offset)); |
| 4329 | // call temp->GetEntryPoint(); |
| 4330 | __ call(Address( |
| 4331 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4332 | } |
| 4333 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4334 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4335 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4336 | size_t size = |
| 4337 | method_patches_.size() + |
| 4338 | relative_call_patches_.size() + |
| 4339 | pc_relative_dex_cache_patches_.size(); |
| 4340 | linker_patches->reserve(size); |
| 4341 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4342 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4343 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4344 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4345 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4346 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4347 | info.target_method.dex_file, |
| 4348 | info.target_method.dex_method_index)); |
| 4349 | } |
| 4350 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4351 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4352 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4353 | info.target_method.dex_file, |
| 4354 | info.target_method.dex_method_index)); |
| 4355 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4356 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4357 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4358 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4359 | &info.target_dex_file, |
| 4360 | GetMethodAddressOffset(), |
| 4361 | info.element_offset)); |
| 4362 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4363 | } |
| 4364 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4365 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4366 | Register card, |
| 4367 | Register object, |
| 4368 | Register value, |
| 4369 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4370 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4371 | if (value_can_be_null) { |
| 4372 | __ testl(value, value); |
| 4373 | __ j(kEqual, &is_null); |
| 4374 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4375 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4376 | __ movl(temp, object); |
| 4377 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4378 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4379 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4380 | if (value_can_be_null) { |
| 4381 | __ Bind(&is_null); |
| 4382 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4383 | } |
| 4384 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4385 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4386 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4387 | |
| 4388 | bool object_field_get_with_read_barrier = |
| 4389 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4390 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4391 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4392 | kEmitCompilerReadBarrier ? |
| 4393 | LocationSummary::kCallOnSlowPath : |
| 4394 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4395 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4396 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4397 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4398 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4399 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4400 | // The output overlaps in case of long: we don't want the low move |
| 4401 | // to overwrite the object's location. Likewise, in the case of |
| 4402 | // an object field get with read barriers enabled, we do not want |
| 4403 | // the move to overwrite the object's location, as we need it to emit |
| 4404 | // the read barrier. |
| 4405 | locations->SetOut( |
| 4406 | Location::RequiresRegister(), |
| 4407 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4408 | Location::kOutputOverlap : |
| 4409 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4410 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4411 | |
| 4412 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4413 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4414 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4415 | // load the temp into the XMM and then copy the XMM into the |
| 4416 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4417 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4418 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4419 | // We need a temporary register for the read barrier marking slow |
| 4420 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4421 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4422 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4423 | } |
| 4424 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4425 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4426 | const FieldInfo& field_info) { |
| 4427 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4428 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4429 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4430 | Location base_loc = locations->InAt(0); |
| 4431 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4432 | Location out = locations->Out(); |
| 4433 | bool is_volatile = field_info.IsVolatile(); |
| 4434 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4435 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4436 | |
| 4437 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4438 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4439 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4440 | break; |
| 4441 | } |
| 4442 | |
| 4443 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4444 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4445 | break; |
| 4446 | } |
| 4447 | |
| 4448 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4449 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4450 | break; |
| 4451 | } |
| 4452 | |
| 4453 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4454 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4455 | break; |
| 4456 | } |
| 4457 | |
| 4458 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4459 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4460 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4461 | |
| 4462 | case Primitive::kPrimNot: { |
| 4463 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4464 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4465 | Location temp_loc = locations->GetTemp(0); |
| 4466 | // Note that a potential implicit null check is handled in this |
| 4467 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4468 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4469 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4470 | if (is_volatile) { |
| 4471 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4472 | } |
| 4473 | } else { |
| 4474 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4475 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4476 | if (is_volatile) { |
| 4477 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4478 | } |
| 4479 | // If read barriers are enabled, emit read barriers other than |
| 4480 | // Baker's using a slow path (and also unpoison the loaded |
| 4481 | // reference, if heap poisoning is enabled). |
| 4482 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4483 | } |
| 4484 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4485 | } |
| 4486 | |
| 4487 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4488 | if (is_volatile) { |
| 4489 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4490 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4491 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4492 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4493 | __ psrlq(temp, Immediate(32)); |
| 4494 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4495 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4496 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4497 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4498 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4499 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4500 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4501 | break; |
| 4502 | } |
| 4503 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4504 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4505 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4506 | break; |
| 4507 | } |
| 4508 | |
| 4509 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4510 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4511 | break; |
| 4512 | } |
| 4513 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4514 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4515 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4516 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4517 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4518 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4519 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4520 | // Potential implicit null checks, in the case of reference or |
| 4521 | // long fields, are handled in the previous switch statement. |
| 4522 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4523 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4524 | } |
| 4525 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4526 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4527 | if (field_type == Primitive::kPrimNot) { |
| 4528 | // Memory barriers, in the case of references, are also handled |
| 4529 | // in the previous switch statement. |
| 4530 | } else { |
| 4531 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4532 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4533 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4534 | } |
| 4535 | |
| 4536 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4537 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4538 | |
| 4539 | LocationSummary* locations = |
| 4540 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4541 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4542 | bool is_volatile = field_info.IsVolatile(); |
| 4543 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4544 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4545 | || (field_type == Primitive::kPrimByte); |
| 4546 | |
| 4547 | // The register allocator does not support multiple |
| 4548 | // inputs that die at entry with one in a specific register. |
| 4549 | if (is_byte_type) { |
| 4550 | // Ensure the value is in a byte register. |
| 4551 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4552 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4553 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4554 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4555 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4556 | } else { |
| 4557 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4558 | } |
| 4559 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4560 | // 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] | 4561 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4562 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4563 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4564 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4565 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4566 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4567 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4568 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4569 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4570 | } else { |
| 4571 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4572 | |
| 4573 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4574 | // Temporary registers for the write barrier. |
| 4575 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4576 | // Ensure the card is in a byte register. |
| 4577 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4578 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4579 | } |
| 4580 | } |
| 4581 | |
| 4582 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4583 | const FieldInfo& field_info, |
| 4584 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4585 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4586 | |
| 4587 | LocationSummary* locations = instruction->GetLocations(); |
| 4588 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4589 | Location value = locations->InAt(1); |
| 4590 | bool is_volatile = field_info.IsVolatile(); |
| 4591 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4592 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4593 | bool needs_write_barrier = |
| 4594 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4595 | |
| 4596 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4597 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4598 | } |
| 4599 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4600 | bool maybe_record_implicit_null_check_done = false; |
| 4601 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4602 | switch (field_type) { |
| 4603 | case Primitive::kPrimBoolean: |
| 4604 | case Primitive::kPrimByte: { |
| 4605 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4606 | break; |
| 4607 | } |
| 4608 | |
| 4609 | case Primitive::kPrimShort: |
| 4610 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4611 | if (value.IsConstant()) { |
| 4612 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4613 | __ movw(Address(base, offset), Immediate(v)); |
| 4614 | } else { |
| 4615 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4616 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4617 | break; |
| 4618 | } |
| 4619 | |
| 4620 | case Primitive::kPrimInt: |
| 4621 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4622 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4623 | // Note that in the case where `value` is a null reference, |
| 4624 | // we do not enter this block, as the reference does not |
| 4625 | // need poisoning. |
| 4626 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4627 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4628 | __ movl(temp, value.AsRegister<Register>()); |
| 4629 | __ PoisonHeapReference(temp); |
| 4630 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4631 | } else if (value.IsConstant()) { |
| 4632 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4633 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4634 | } else { |
| 4635 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4636 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4637 | break; |
| 4638 | } |
| 4639 | |
| 4640 | case Primitive::kPrimLong: { |
| 4641 | if (is_volatile) { |
| 4642 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4643 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4644 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4645 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4646 | __ punpckldq(temp1, temp2); |
| 4647 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4648 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4649 | } else if (value.IsConstant()) { |
| 4650 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4651 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4652 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4653 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4654 | } else { |
| 4655 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4656 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4657 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4658 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4659 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4660 | break; |
| 4661 | } |
| 4662 | |
| 4663 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4664 | if (value.IsConstant()) { |
| 4665 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4666 | __ movl(Address(base, offset), Immediate(v)); |
| 4667 | } else { |
| 4668 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4669 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4670 | break; |
| 4671 | } |
| 4672 | |
| 4673 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4674 | if (value.IsConstant()) { |
| 4675 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4676 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4677 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4678 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4679 | maybe_record_implicit_null_check_done = true; |
| 4680 | } else { |
| 4681 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4682 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4683 | break; |
| 4684 | } |
| 4685 | |
| 4686 | case Primitive::kPrimVoid: |
| 4687 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4688 | UNREACHABLE(); |
| 4689 | } |
| 4690 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4691 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4692 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4693 | } |
| 4694 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4695 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4696 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4697 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4698 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4699 | } |
| 4700 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4701 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4702 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4703 | } |
| 4704 | } |
| 4705 | |
| 4706 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4707 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4708 | } |
| 4709 | |
| 4710 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4711 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4712 | } |
| 4713 | |
| 4714 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4715 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4716 | } |
| 4717 | |
| 4718 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4719 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4723 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4724 | } |
| 4725 | |
| 4726 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4727 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4731 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4732 | } |
| 4733 | |
| 4734 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4735 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4736 | } |
| 4737 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4738 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4739 | HUnresolvedInstanceFieldGet* instruction) { |
| 4740 | FieldAccessCallingConventionX86 calling_convention; |
| 4741 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4742 | instruction, instruction->GetFieldType(), calling_convention); |
| 4743 | } |
| 4744 | |
| 4745 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4746 | HUnresolvedInstanceFieldGet* instruction) { |
| 4747 | FieldAccessCallingConventionX86 calling_convention; |
| 4748 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4749 | instruction->GetFieldType(), |
| 4750 | instruction->GetFieldIndex(), |
| 4751 | instruction->GetDexPc(), |
| 4752 | calling_convention); |
| 4753 | } |
| 4754 | |
| 4755 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4756 | HUnresolvedInstanceFieldSet* instruction) { |
| 4757 | FieldAccessCallingConventionX86 calling_convention; |
| 4758 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4759 | instruction, instruction->GetFieldType(), calling_convention); |
| 4760 | } |
| 4761 | |
| 4762 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4763 | HUnresolvedInstanceFieldSet* instruction) { |
| 4764 | FieldAccessCallingConventionX86 calling_convention; |
| 4765 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4766 | instruction->GetFieldType(), |
| 4767 | instruction->GetFieldIndex(), |
| 4768 | instruction->GetDexPc(), |
| 4769 | calling_convention); |
| 4770 | } |
| 4771 | |
| 4772 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4773 | HUnresolvedStaticFieldGet* instruction) { |
| 4774 | FieldAccessCallingConventionX86 calling_convention; |
| 4775 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4776 | instruction, instruction->GetFieldType(), calling_convention); |
| 4777 | } |
| 4778 | |
| 4779 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4780 | HUnresolvedStaticFieldGet* instruction) { |
| 4781 | FieldAccessCallingConventionX86 calling_convention; |
| 4782 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4783 | instruction->GetFieldType(), |
| 4784 | instruction->GetFieldIndex(), |
| 4785 | instruction->GetDexPc(), |
| 4786 | calling_convention); |
| 4787 | } |
| 4788 | |
| 4789 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4790 | HUnresolvedStaticFieldSet* instruction) { |
| 4791 | FieldAccessCallingConventionX86 calling_convention; |
| 4792 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4793 | instruction, instruction->GetFieldType(), calling_convention); |
| 4794 | } |
| 4795 | |
| 4796 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4797 | HUnresolvedStaticFieldSet* instruction) { |
| 4798 | FieldAccessCallingConventionX86 calling_convention; |
| 4799 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4800 | instruction->GetFieldType(), |
| 4801 | instruction->GetFieldIndex(), |
| 4802 | instruction->GetDexPc(), |
| 4803 | calling_convention); |
| 4804 | } |
| 4805 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4806 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4807 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4808 | ? LocationSummary::kCallOnSlowPath |
| 4809 | : LocationSummary::kNoCall; |
| 4810 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4811 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4812 | ? Location::RequiresRegister() |
| 4813 | : Location::Any(); |
| 4814 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4815 | if (instruction->HasUses()) { |
| 4816 | locations->SetOut(Location::SameAsFirstInput()); |
| 4817 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4818 | } |
| 4819 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4820 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4821 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4822 | return; |
| 4823 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4824 | LocationSummary* locations = instruction->GetLocations(); |
| 4825 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4826 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4827 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4828 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4829 | } |
| 4830 | |
| 4831 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4832 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4833 | codegen_->AddSlowPath(slow_path); |
| 4834 | |
| 4835 | LocationSummary* locations = instruction->GetLocations(); |
| 4836 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4837 | |
| 4838 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4839 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4840 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4841 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4842 | } else { |
| 4843 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4844 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4845 | __ jmp(slow_path->GetEntryLabel()); |
| 4846 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4847 | } |
| 4848 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4849 | } |
| 4850 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4851 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4852 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4853 | GenerateImplicitNullCheck(instruction); |
| 4854 | } else { |
| 4855 | GenerateExplicitNullCheck(instruction); |
| 4856 | } |
| 4857 | } |
| 4858 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4859 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4860 | bool object_array_get_with_read_barrier = |
| 4861 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4862 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4863 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4864 | object_array_get_with_read_barrier ? |
| 4865 | LocationSummary::kCallOnSlowPath : |
| 4866 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4867 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4868 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4869 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4870 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4871 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4872 | // The output overlaps in case of long: we don't want the low move |
| 4873 | // to overwrite the array's location. Likewise, in the case of an |
| 4874 | // object array get with read barriers enabled, we do not want the |
| 4875 | // move to overwrite the array's location, as we need it to emit |
| 4876 | // the read barrier. |
| 4877 | locations->SetOut( |
| 4878 | Location::RequiresRegister(), |
| 4879 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 4880 | Location::kOutputOverlap : |
| 4881 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4882 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4883 | // We need a temporary register for the read barrier marking slow |
| 4884 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 4885 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4886 | locations->AddTemp(Location::RequiresRegister()); |
| 4887 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4888 | } |
| 4889 | |
| 4890 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4891 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4892 | Location obj_loc = locations->InAt(0); |
| 4893 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4894 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4895 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4896 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4897 | Primitive::Type type = instruction->GetType(); |
| 4898 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4899 | case Primitive::kPrimBoolean: { |
| 4900 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4901 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4902 | if (index.IsConstant()) { |
| 4903 | __ movzxb(out, Address(obj, |
| 4904 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4905 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4906 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4907 | } |
| 4908 | break; |
| 4909 | } |
| 4910 | |
| 4911 | case Primitive::kPrimByte: { |
| 4912 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4913 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4914 | if (index.IsConstant()) { |
| 4915 | __ movsxb(out, Address(obj, |
| 4916 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4917 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4918 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4919 | } |
| 4920 | break; |
| 4921 | } |
| 4922 | |
| 4923 | case Primitive::kPrimShort: { |
| 4924 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4925 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4926 | if (index.IsConstant()) { |
| 4927 | __ movsxw(out, Address(obj, |
| 4928 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4929 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4930 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4931 | } |
| 4932 | break; |
| 4933 | } |
| 4934 | |
| 4935 | case Primitive::kPrimChar: { |
| 4936 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4937 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4938 | if (index.IsConstant()) { |
| 4939 | __ movzxw(out, Address(obj, |
| 4940 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4941 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4942 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4943 | } |
| 4944 | break; |
| 4945 | } |
| 4946 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4947 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4948 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4949 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4950 | if (index.IsConstant()) { |
| 4951 | __ movl(out, Address(obj, |
| 4952 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4953 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4954 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4955 | } |
| 4956 | break; |
| 4957 | } |
| 4958 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4959 | case Primitive::kPrimNot: { |
| 4960 | static_assert( |
| 4961 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 4962 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 4963 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4964 | // /* HeapReference<Object> */ out = |
| 4965 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 4966 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4967 | Location temp = locations->GetTemp(0); |
| 4968 | // Note that a potential implicit null check is handled in this |
| 4969 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 4970 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 4971 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 4972 | } else { |
| 4973 | Register out = out_loc.AsRegister<Register>(); |
| 4974 | if (index.IsConstant()) { |
| 4975 | uint32_t offset = |
| 4976 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 4977 | __ movl(out, Address(obj, offset)); |
| 4978 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4979 | // If read barriers are enabled, emit read barriers other than |
| 4980 | // Baker's using a slow path (and also unpoison the loaded |
| 4981 | // reference, if heap poisoning is enabled). |
| 4982 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 4983 | } else { |
| 4984 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4985 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4986 | // If read barriers are enabled, emit read barriers other than |
| 4987 | // Baker's using a slow path (and also unpoison the loaded |
| 4988 | // reference, if heap poisoning is enabled). |
| 4989 | codegen_->MaybeGenerateReadBarrierSlow( |
| 4990 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 4991 | } |
| 4992 | } |
| 4993 | break; |
| 4994 | } |
| 4995 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4996 | case Primitive::kPrimLong: { |
| 4997 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4998 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4999 | if (index.IsConstant()) { |
| 5000 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5001 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5002 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5003 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5004 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5005 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5006 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5007 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5008 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5009 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5010 | } |
| 5011 | break; |
| 5012 | } |
| 5013 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5014 | case Primitive::kPrimFloat: { |
| 5015 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5016 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5017 | if (index.IsConstant()) { |
| 5018 | __ movss(out, Address(obj, |
| 5019 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5020 | } else { |
| 5021 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5022 | } |
| 5023 | break; |
| 5024 | } |
| 5025 | |
| 5026 | case Primitive::kPrimDouble: { |
| 5027 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5028 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5029 | if (index.IsConstant()) { |
| 5030 | __ movsd(out, Address(obj, |
| 5031 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5032 | } else { |
| 5033 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5034 | } |
| 5035 | break; |
| 5036 | } |
| 5037 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5038 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5039 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5040 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5041 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5042 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5043 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5044 | // Potential implicit null checks, in the case of reference or |
| 5045 | // long arrays, are handled in the previous switch statement. |
| 5046 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5047 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5048 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5049 | } |
| 5050 | |
| 5051 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 5052 | // This location builder might end up asking to up to four registers, which is |
| 5053 | // not currently possible for baseline. The situation in which we need four |
| 5054 | // registers cannot be met by baseline though, because it has not run any |
| 5055 | // optimization. |
| 5056 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5057 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5058 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5059 | bool needs_write_barrier = |
| 5060 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5061 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5062 | bool object_array_set_with_read_barrier = |
| 5063 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5064 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5065 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5066 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5067 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5068 | LocationSummary::kCallOnSlowPath : |
| 5069 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5070 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5071 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5072 | || (value_type == Primitive::kPrimByte); |
| 5073 | // We need the inputs to be different than the output in case of long operation. |
| 5074 | // In case of a byte operation, the register allocator does not support multiple |
| 5075 | // inputs that die at entry with one in a specific register. |
| 5076 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5077 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5078 | if (is_byte_type) { |
| 5079 | // Ensure the value is in a byte register. |
| 5080 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5081 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5082 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5083 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5084 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5085 | } |
| 5086 | if (needs_write_barrier) { |
| 5087 | // Temporary registers for the write barrier. |
| 5088 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5089 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5090 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5091 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5092 | } |
| 5093 | |
| 5094 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5095 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5096 | Location array_loc = locations->InAt(0); |
| 5097 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5098 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5099 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5100 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5101 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5102 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5103 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5104 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5105 | bool needs_write_barrier = |
| 5106 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5107 | |
| 5108 | switch (value_type) { |
| 5109 | case Primitive::kPrimBoolean: |
| 5110 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5111 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5112 | Address address = index.IsConstant() |
| 5113 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5114 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5115 | if (value.IsRegister()) { |
| 5116 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5117 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5118 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5119 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5120 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5121 | break; |
| 5122 | } |
| 5123 | |
| 5124 | case Primitive::kPrimShort: |
| 5125 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5126 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5127 | Address address = index.IsConstant() |
| 5128 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5129 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5130 | if (value.IsRegister()) { |
| 5131 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5132 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5133 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5134 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5135 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5136 | break; |
| 5137 | } |
| 5138 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5139 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5140 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5141 | Address address = index.IsConstant() |
| 5142 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5143 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5144 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5145 | if (!value.IsRegister()) { |
| 5146 | // Just setting null. |
| 5147 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5148 | DCHECK(value.IsConstant()) << value; |
| 5149 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5150 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5151 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5152 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5153 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5154 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5155 | |
| 5156 | DCHECK(needs_write_barrier); |
| 5157 | Register register_value = value.AsRegister<Register>(); |
| 5158 | NearLabel done, not_null, do_put; |
| 5159 | SlowPathCode* slow_path = nullptr; |
| 5160 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5161 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5162 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5163 | codegen_->AddSlowPath(slow_path); |
| 5164 | if (instruction->GetValueCanBeNull()) { |
| 5165 | __ testl(register_value, register_value); |
| 5166 | __ j(kNotEqual, ¬_null); |
| 5167 | __ movl(address, Immediate(0)); |
| 5168 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5169 | __ jmp(&done); |
| 5170 | __ Bind(¬_null); |
| 5171 | } |
| 5172 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5173 | if (kEmitCompilerReadBarrier) { |
| 5174 | // When read barriers are enabled, the type checking |
| 5175 | // instrumentation requires two read barriers: |
| 5176 | // |
| 5177 | // __ movl(temp2, temp); |
| 5178 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5179 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5180 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5181 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5182 | // |
| 5183 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5184 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5185 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5186 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5187 | // |
| 5188 | // __ cmpl(temp, temp2); |
| 5189 | // |
| 5190 | // However, the second read barrier may trash `temp`, as it |
| 5191 | // is a temporary register, and as such would not be saved |
| 5192 | // along with live registers before calling the runtime (nor |
| 5193 | // restored afterwards). So in this case, we bail out and |
| 5194 | // delegate the work to the array set slow path. |
| 5195 | // |
| 5196 | // TODO: Extend the register allocator to support a new |
| 5197 | // "(locally) live temp" location so as to avoid always |
| 5198 | // going into the slow path when read barriers are enabled. |
| 5199 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5200 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5201 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5202 | __ movl(temp, Address(array, class_offset)); |
| 5203 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5204 | __ MaybeUnpoisonHeapReference(temp); |
| 5205 | |
| 5206 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5207 | __ movl(temp, Address(temp, component_offset)); |
| 5208 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5209 | // nor the object reference in `register_value->klass`, as |
| 5210 | // we are comparing two poisoned references. |
| 5211 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5212 | |
| 5213 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5214 | __ j(kEqual, &do_put); |
| 5215 | // If heap poisoning is enabled, the `temp` reference has |
| 5216 | // not been unpoisoned yet; unpoison it now. |
| 5217 | __ MaybeUnpoisonHeapReference(temp); |
| 5218 | |
| 5219 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5220 | __ movl(temp, Address(temp, super_offset)); |
| 5221 | // If heap poisoning is enabled, no need to unpoison |
| 5222 | // `temp`, as we are comparing against null below. |
| 5223 | __ testl(temp, temp); |
| 5224 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5225 | __ Bind(&do_put); |
| 5226 | } else { |
| 5227 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5228 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5229 | } |
| 5230 | } |
| 5231 | |
| 5232 | if (kPoisonHeapReferences) { |
| 5233 | __ movl(temp, register_value); |
| 5234 | __ PoisonHeapReference(temp); |
| 5235 | __ movl(address, temp); |
| 5236 | } else { |
| 5237 | __ movl(address, register_value); |
| 5238 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5239 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5240 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5241 | } |
| 5242 | |
| 5243 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5244 | codegen_->MarkGCCard( |
| 5245 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5246 | __ Bind(&done); |
| 5247 | |
| 5248 | if (slow_path != nullptr) { |
| 5249 | __ Bind(slow_path->GetExitLabel()); |
| 5250 | } |
| 5251 | |
| 5252 | break; |
| 5253 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5254 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5255 | case Primitive::kPrimInt: { |
| 5256 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5257 | Address address = index.IsConstant() |
| 5258 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5259 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5260 | if (value.IsRegister()) { |
| 5261 | __ movl(address, value.AsRegister<Register>()); |
| 5262 | } else { |
| 5263 | DCHECK(value.IsConstant()) << value; |
| 5264 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5265 | __ movl(address, Immediate(v)); |
| 5266 | } |
| 5267 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5268 | break; |
| 5269 | } |
| 5270 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5271 | case Primitive::kPrimLong: { |
| 5272 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5273 | if (index.IsConstant()) { |
| 5274 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5275 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5276 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5277 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5278 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5279 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5280 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5281 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5282 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5283 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5284 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5285 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5286 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5287 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5288 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5289 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5290 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5291 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5292 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5293 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5294 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5295 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5296 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5297 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5298 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5299 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5300 | Immediate(High32Bits(val))); |
| 5301 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5302 | } |
| 5303 | break; |
| 5304 | } |
| 5305 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5306 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5307 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5308 | Address address = index.IsConstant() |
| 5309 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5310 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5311 | if (value.IsFpuRegister()) { |
| 5312 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5313 | } else { |
| 5314 | DCHECK(value.IsConstant()); |
| 5315 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5316 | __ movl(address, Immediate(v)); |
| 5317 | } |
| 5318 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5319 | break; |
| 5320 | } |
| 5321 | |
| 5322 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5323 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5324 | Address address = index.IsConstant() |
| 5325 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5326 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5327 | if (value.IsFpuRegister()) { |
| 5328 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5329 | } else { |
| 5330 | DCHECK(value.IsConstant()); |
| 5331 | Address address_hi = index.IsConstant() ? |
| 5332 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5333 | offset + kX86WordSize) : |
| 5334 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5335 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5336 | __ movl(address, Immediate(Low32Bits(v))); |
| 5337 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5338 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5339 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5340 | break; |
| 5341 | } |
| 5342 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5343 | case Primitive::kPrimVoid: |
| 5344 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5345 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5346 | } |
| 5347 | } |
| 5348 | |
| 5349 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5350 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5352 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5353 | } |
| 5354 | |
| 5355 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5356 | LocationSummary* locations = instruction->GetLocations(); |
| 5357 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5358 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5359 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5360 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5361 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5362 | } |
| 5363 | |
| 5364 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5365 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5366 | ? LocationSummary::kCallOnSlowPath |
| 5367 | : LocationSummary::kNoCall; |
| 5368 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5369 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5370 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5371 | if (instruction->HasUses()) { |
| 5372 | locations->SetOut(Location::SameAsFirstInput()); |
| 5373 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5377 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5378 | Location index_loc = locations->InAt(0); |
| 5379 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5380 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5381 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5382 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5383 | if (length_loc.IsConstant()) { |
| 5384 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5385 | if (index_loc.IsConstant()) { |
| 5386 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5387 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5388 | if (index < 0 || index >= length) { |
| 5389 | codegen_->AddSlowPath(slow_path); |
| 5390 | __ jmp(slow_path->GetEntryLabel()); |
| 5391 | } else { |
| 5392 | // Some optimization after BCE may have generated this, and we should not |
| 5393 | // generate a bounds check if it is a valid range. |
| 5394 | } |
| 5395 | return; |
| 5396 | } |
| 5397 | |
| 5398 | // We have to reverse the jump condition because the length is the constant. |
| 5399 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5400 | __ cmpl(index_reg, Immediate(length)); |
| 5401 | codegen_->AddSlowPath(slow_path); |
| 5402 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5403 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5404 | Register length = length_loc.AsRegister<Register>(); |
| 5405 | if (index_loc.IsConstant()) { |
| 5406 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5407 | __ cmpl(length, Immediate(value)); |
| 5408 | } else { |
| 5409 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5410 | } |
| 5411 | codegen_->AddSlowPath(slow_path); |
| 5412 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5413 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5414 | } |
| 5415 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5416 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 5417 | temp->SetLocations(nullptr); |
| 5418 | } |
| 5419 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5420 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5421 | // Nothing to do, this is driven by the code generator. |
| 5422 | } |
| 5423 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5424 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5425 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5426 | } |
| 5427 | |
| 5428 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5429 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5430 | } |
| 5431 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5432 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5433 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5434 | } |
| 5435 | |
| 5436 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5437 | HBasicBlock* block = instruction->GetBlock(); |
| 5438 | if (block->GetLoopInformation() != nullptr) { |
| 5439 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5440 | // The back edge will generate the suspend check. |
| 5441 | return; |
| 5442 | } |
| 5443 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5444 | // The goto will generate the suspend check. |
| 5445 | return; |
| 5446 | } |
| 5447 | GenerateSuspendCheck(instruction, nullptr); |
| 5448 | } |
| 5449 | |
| 5450 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5451 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5452 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5453 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5454 | if (slow_path == nullptr) { |
| 5455 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5456 | instruction->SetSlowPath(slow_path); |
| 5457 | codegen_->AddSlowPath(slow_path); |
| 5458 | if (successor != nullptr) { |
| 5459 | DCHECK(successor->IsLoopHeader()); |
| 5460 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5461 | } |
| 5462 | } else { |
| 5463 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5464 | } |
| 5465 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5466 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5467 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5468 | if (successor == nullptr) { |
| 5469 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5470 | __ Bind(slow_path->GetReturnLabel()); |
| 5471 | } else { |
| 5472 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5473 | __ jmp(slow_path->GetEntryLabel()); |
| 5474 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5475 | } |
| 5476 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5477 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5478 | return codegen_->GetAssembler(); |
| 5479 | } |
| 5480 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5481 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5482 | ScratchRegisterScope ensure_scratch( |
| 5483 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5484 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5485 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5486 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5487 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5491 | ScratchRegisterScope ensure_scratch( |
| 5492 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5493 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5494 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5495 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5496 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5497 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5498 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5502 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5503 | Location source = move->GetSource(); |
| 5504 | Location destination = move->GetDestination(); |
| 5505 | |
| 5506 | if (source.IsRegister()) { |
| 5507 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5508 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5509 | } else { |
| 5510 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5511 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5512 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5513 | } else if (source.IsFpuRegister()) { |
| 5514 | if (destination.IsFpuRegister()) { |
| 5515 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5516 | } else if (destination.IsStackSlot()) { |
| 5517 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5518 | } else { |
| 5519 | DCHECK(destination.IsDoubleStackSlot()); |
| 5520 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5521 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5522 | } else if (source.IsStackSlot()) { |
| 5523 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5524 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5525 | } else if (destination.IsFpuRegister()) { |
| 5526 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5527 | } else { |
| 5528 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5529 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5530 | } |
| 5531 | } else if (source.IsDoubleStackSlot()) { |
| 5532 | if (destination.IsFpuRegister()) { |
| 5533 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5534 | } else { |
| 5535 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5536 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5537 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5538 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5539 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5540 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5541 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5542 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5543 | if (value == 0) { |
| 5544 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5545 | } else { |
| 5546 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5547 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5548 | } else { |
| 5549 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5550 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5551 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5552 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5553 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5554 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5555 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5556 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5557 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5558 | if (value == 0) { |
| 5559 | // Easy handling of 0.0. |
| 5560 | __ xorps(dest, dest); |
| 5561 | } else { |
| 5562 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5563 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5564 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5565 | __ movl(temp, Immediate(value)); |
| 5566 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5567 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5568 | } else { |
| 5569 | DCHECK(destination.IsStackSlot()) << destination; |
| 5570 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5571 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5572 | } else if (constant->IsLongConstant()) { |
| 5573 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5574 | int32_t low_value = Low32Bits(value); |
| 5575 | int32_t high_value = High32Bits(value); |
| 5576 | Immediate low(low_value); |
| 5577 | Immediate high(high_value); |
| 5578 | if (destination.IsDoubleStackSlot()) { |
| 5579 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5580 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5581 | } else { |
| 5582 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5583 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5584 | } |
| 5585 | } else { |
| 5586 | DCHECK(constant->IsDoubleConstant()); |
| 5587 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5588 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5589 | int32_t low_value = Low32Bits(value); |
| 5590 | int32_t high_value = High32Bits(value); |
| 5591 | Immediate low(low_value); |
| 5592 | Immediate high(high_value); |
| 5593 | if (destination.IsFpuRegister()) { |
| 5594 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5595 | if (value == 0) { |
| 5596 | // Easy handling of 0.0. |
| 5597 | __ xorpd(dest, dest); |
| 5598 | } else { |
| 5599 | __ pushl(high); |
| 5600 | __ pushl(low); |
| 5601 | __ movsd(dest, Address(ESP, 0)); |
| 5602 | __ addl(ESP, Immediate(8)); |
| 5603 | } |
| 5604 | } else { |
| 5605 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5606 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5607 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5608 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5609 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5610 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5611 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5612 | } |
| 5613 | } |
| 5614 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5615 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5616 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5617 | ScratchRegisterScope ensure_scratch( |
| 5618 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5619 | |
| 5620 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5621 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5622 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5623 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5624 | } |
| 5625 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5626 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5627 | ScratchRegisterScope ensure_scratch( |
| 5628 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5629 | |
| 5630 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5631 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5632 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5633 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5634 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5635 | } |
| 5636 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5637 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5638 | ScratchRegisterScope ensure_scratch1( |
| 5639 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5640 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5641 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5642 | ScratchRegisterScope ensure_scratch2( |
| 5643 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5644 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5645 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5646 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5647 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5648 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5649 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5650 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5651 | } |
| 5652 | |
| 5653 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5654 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5655 | Location source = move->GetSource(); |
| 5656 | Location destination = move->GetDestination(); |
| 5657 | |
| 5658 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5659 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5660 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5661 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5662 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5663 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5664 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5665 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5666 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5667 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5668 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5669 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5670 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5671 | // Use XOR Swap algorithm to avoid a temporary. |
| 5672 | DCHECK_NE(source.reg(), destination.reg()); |
| 5673 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5674 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5675 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5676 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5677 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5678 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5679 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5680 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5681 | // Take advantage of the 16 bytes in the XMM register. |
| 5682 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5683 | Address stack(ESP, destination.GetStackIndex()); |
| 5684 | // Load the double into the high doubleword. |
| 5685 | __ movhpd(reg, stack); |
| 5686 | |
| 5687 | // Store the low double into the destination. |
| 5688 | __ movsd(stack, reg); |
| 5689 | |
| 5690 | // Move the high double to the low double. |
| 5691 | __ psrldq(reg, Immediate(8)); |
| 5692 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5693 | // Take advantage of the 16 bytes in the XMM register. |
| 5694 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5695 | Address stack(ESP, source.GetStackIndex()); |
| 5696 | // Load the double into the high doubleword. |
| 5697 | __ movhpd(reg, stack); |
| 5698 | |
| 5699 | // Store the low double into the destination. |
| 5700 | __ movsd(stack, reg); |
| 5701 | |
| 5702 | // Move the high double to the low double. |
| 5703 | __ psrldq(reg, Immediate(8)); |
| 5704 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5705 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5706 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5707 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5708 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5709 | } |
| 5710 | } |
| 5711 | |
| 5712 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5713 | __ pushl(static_cast<Register>(reg)); |
| 5714 | } |
| 5715 | |
| 5716 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5717 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5718 | } |
| 5719 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5720 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5721 | InvokeRuntimeCallingConvention calling_convention; |
| 5722 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5723 | cls, |
| 5724 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5725 | Location::RegisterLocation(EAX), |
| 5726 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5727 | } |
| 5728 | |
| 5729 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5730 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5731 | if (cls->NeedsAccessCheck()) { |
| 5732 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5733 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5734 | cls, |
| 5735 | cls->GetDexPc(), |
| 5736 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5737 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5738 | return; |
| 5739 | } |
| 5740 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5741 | Location out_loc = locations->Out(); |
| 5742 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5743 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5744 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5745 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5746 | DCHECK(!cls->CanCallRuntime()); |
| 5747 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5748 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5749 | GenerateGcRootFieldLoad( |
| 5750 | cls, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5751 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5752 | // /* GcRoot<mirror::Class>[] */ out = |
| 5753 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5754 | __ movl(out, Address(current_method, |
| 5755 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5756 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
| 5757 | GenerateGcRootFieldLoad(cls, out_loc, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5758 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5759 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5760 | DCHECK(cls->CanCallRuntime()); |
| 5761 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5762 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5763 | codegen_->AddSlowPath(slow_path); |
| 5764 | |
| 5765 | if (!cls->IsInDexCache()) { |
| 5766 | __ testl(out, out); |
| 5767 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5768 | } |
| 5769 | |
| 5770 | if (cls->MustGenerateClinitCheck()) { |
| 5771 | GenerateClassInitializationCheck(slow_path, out); |
| 5772 | } else { |
| 5773 | __ Bind(slow_path->GetExitLabel()); |
| 5774 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5775 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5780 | LocationSummary* locations = |
| 5781 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5782 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5783 | if (check->HasUses()) { |
| 5784 | locations->SetOut(Location::SameAsFirstInput()); |
| 5785 | } |
| 5786 | } |
| 5787 | |
| 5788 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5789 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5790 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5791 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5792 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5793 | GenerateClassInitializationCheck(slow_path, |
| 5794 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5795 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5796 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5797 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5798 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5799 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5800 | Immediate(mirror::Class::kStatusInitialized)); |
| 5801 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5802 | __ Bind(slow_path->GetExitLabel()); |
| 5803 | // No need for memory fence, thanks to the X86 memory model. |
| 5804 | } |
| 5805 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5806 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5807 | LocationSummary::CallKind call_kind = (!load->IsInDexCache() || kEmitCompilerReadBarrier) |
| 5808 | ? LocationSummary::kCallOnSlowPath |
| 5809 | : LocationSummary::kNoCall; |
| 5810 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5811 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5812 | locations->SetOut(Location::RequiresRegister()); |
| 5813 | } |
| 5814 | |
| 5815 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5816 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5817 | Location out_loc = locations->Out(); |
| 5818 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5819 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5820 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5821 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5822 | GenerateGcRootFieldLoad( |
| 5823 | load, out_loc, current_method, ArtMethod::DeclaringClassOffset().Int32Value()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5824 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5825 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5826 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 5827 | GenerateGcRootFieldLoad( |
| 5828 | load, out_loc, out, CodeGenerator::GetCacheOffset(load->GetStringIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5829 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5830 | if (!load->IsInDexCache()) { |
| 5831 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 5832 | codegen_->AddSlowPath(slow_path); |
| 5833 | __ testl(out, out); |
| 5834 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5835 | __ Bind(slow_path->GetExitLabel()); |
| 5836 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5837 | } |
| 5838 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5839 | static Address GetExceptionTlsAddress() { |
| 5840 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5841 | } |
| 5842 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5843 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5844 | LocationSummary* locations = |
| 5845 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5846 | locations->SetOut(Location::RequiresRegister()); |
| 5847 | } |
| 5848 | |
| 5849 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5850 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5851 | } |
| 5852 | |
| 5853 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5854 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5855 | } |
| 5856 | |
| 5857 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5858 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5859 | } |
| 5860 | |
| 5861 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5862 | LocationSummary* locations = |
| 5863 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5864 | InvokeRuntimeCallingConvention calling_convention; |
| 5865 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5866 | } |
| 5867 | |
| 5868 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5869 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5870 | instruction, |
| 5871 | instruction->GetDexPc(), |
| 5872 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5873 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5874 | } |
| 5875 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5876 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 5877 | return kEmitCompilerReadBarrier && |
| 5878 | (kUseBakerReadBarrier || |
| 5879 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 5880 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 5881 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 5882 | } |
| 5883 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5884 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5885 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5886 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 5887 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5888 | case TypeCheckKind::kExactCheck: |
| 5889 | case TypeCheckKind::kAbstractClassCheck: |
| 5890 | case TypeCheckKind::kClassHierarchyCheck: |
| 5891 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5892 | call_kind = |
| 5893 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5894 | break; |
| 5895 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5896 | case TypeCheckKind::kUnresolvedCheck: |
| 5897 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5898 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5899 | break; |
| 5900 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5901 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5902 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5903 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5904 | locations->SetInAt(1, Location::Any()); |
| 5905 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 5906 | locations->SetOut(Location::RequiresRegister()); |
| 5907 | // When read barriers are enabled, we need a temporary register for |
| 5908 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5909 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5910 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5911 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5912 | } |
| 5913 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5914 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5915 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5916 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5917 | Location obj_loc = locations->InAt(0); |
| 5918 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5919 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5920 | Location out_loc = locations->Out(); |
| 5921 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5922 | Location temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 5923 | locations->GetTemp(0) : |
| 5924 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5925 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5926 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5927 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5928 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5929 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5930 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5931 | |
| 5932 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5933 | // Avoid null check if we know obj is not null. |
| 5934 | if (instruction->MustDoNullCheck()) { |
| 5935 | __ testl(obj, obj); |
| 5936 | __ j(kEqual, &zero); |
| 5937 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5938 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5939 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5940 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5941 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5942 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5943 | case TypeCheckKind::kExactCheck: { |
| 5944 | if (cls.IsRegister()) { |
| 5945 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5946 | } else { |
| 5947 | DCHECK(cls.IsStackSlot()) << cls; |
| 5948 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5949 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5950 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5951 | // Classes must be equal for the instanceof to succeed. |
| 5952 | __ j(kNotEqual, &zero); |
| 5953 | __ movl(out, Immediate(1)); |
| 5954 | __ jmp(&done); |
| 5955 | break; |
| 5956 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5957 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5958 | case TypeCheckKind::kAbstractClassCheck: { |
| 5959 | // If the class is abstract, we eagerly fetch the super class of the |
| 5960 | // object to avoid doing a comparison we know will fail. |
| 5961 | NearLabel loop; |
| 5962 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5963 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5964 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5965 | __ testl(out, out); |
| 5966 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5967 | __ j(kEqual, &done); |
| 5968 | if (cls.IsRegister()) { |
| 5969 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5970 | } else { |
| 5971 | DCHECK(cls.IsStackSlot()) << cls; |
| 5972 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5973 | } |
| 5974 | __ j(kNotEqual, &loop); |
| 5975 | __ movl(out, Immediate(1)); |
| 5976 | if (zero.IsLinked()) { |
| 5977 | __ jmp(&done); |
| 5978 | } |
| 5979 | break; |
| 5980 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5981 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5982 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5983 | // Walk over the class hierarchy to find a match. |
| 5984 | NearLabel loop, success; |
| 5985 | __ Bind(&loop); |
| 5986 | if (cls.IsRegister()) { |
| 5987 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5988 | } else { |
| 5989 | DCHECK(cls.IsStackSlot()) << cls; |
| 5990 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5991 | } |
| 5992 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5993 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5994 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5995 | __ testl(out, out); |
| 5996 | __ j(kNotEqual, &loop); |
| 5997 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5998 | __ jmp(&done); |
| 5999 | __ Bind(&success); |
| 6000 | __ movl(out, Immediate(1)); |
| 6001 | if (zero.IsLinked()) { |
| 6002 | __ jmp(&done); |
| 6003 | } |
| 6004 | break; |
| 6005 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6006 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6007 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6008 | // Do an exact check. |
| 6009 | NearLabel exact_check; |
| 6010 | if (cls.IsRegister()) { |
| 6011 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6012 | } else { |
| 6013 | DCHECK(cls.IsStackSlot()) << cls; |
| 6014 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6015 | } |
| 6016 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6017 | // 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] | 6018 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6019 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6020 | __ testl(out, out); |
| 6021 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6022 | __ j(kEqual, &done); |
| 6023 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6024 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6025 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6026 | __ movl(out, Immediate(1)); |
| 6027 | __ jmp(&done); |
| 6028 | break; |
| 6029 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6030 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6031 | case TypeCheckKind::kArrayCheck: { |
| 6032 | if (cls.IsRegister()) { |
| 6033 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6034 | } else { |
| 6035 | DCHECK(cls.IsStackSlot()) << cls; |
| 6036 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6037 | } |
| 6038 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6039 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6040 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6041 | codegen_->AddSlowPath(slow_path); |
| 6042 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6043 | __ movl(out, Immediate(1)); |
| 6044 | if (zero.IsLinked()) { |
| 6045 | __ jmp(&done); |
| 6046 | } |
| 6047 | break; |
| 6048 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6049 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6050 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6051 | case TypeCheckKind::kInterfaceCheck: { |
| 6052 | // Note that we indeed only call on slow path, but we always go |
| 6053 | // into the slow path for the unresolved & interface check |
| 6054 | // cases. |
| 6055 | // |
| 6056 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6057 | // entry point without resorting to a type checking slow path |
| 6058 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6059 | // require to assign fixed registers for the inputs of this |
| 6060 | // HInstanceOf instruction (following the runtime calling |
| 6061 | // convention), which might be cluttered by the potential first |
| 6062 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6063 | // |
| 6064 | // TODO: Introduce a new runtime entry point taking the object |
| 6065 | // to test (instead of its class) as argument, and let it deal |
| 6066 | // with the read barrier issues. This will let us refactor this |
| 6067 | // case of the `switch` code as it was previously (with a direct |
| 6068 | // call to the runtime not using a type checking slow path). |
| 6069 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6070 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6071 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6072 | /* is_fatal */ false); |
| 6073 | codegen_->AddSlowPath(slow_path); |
| 6074 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6075 | if (zero.IsLinked()) { |
| 6076 | __ jmp(&done); |
| 6077 | } |
| 6078 | break; |
| 6079 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6080 | } |
| 6081 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6082 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6083 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6084 | __ xorl(out, out); |
| 6085 | } |
| 6086 | |
| 6087 | if (done.IsLinked()) { |
| 6088 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6089 | } |
| 6090 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6091 | if (slow_path != nullptr) { |
| 6092 | __ Bind(slow_path->GetExitLabel()); |
| 6093 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6094 | } |
| 6095 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6096 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6097 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6098 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6099 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6100 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6101 | case TypeCheckKind::kExactCheck: |
| 6102 | case TypeCheckKind::kAbstractClassCheck: |
| 6103 | case TypeCheckKind::kClassHierarchyCheck: |
| 6104 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6105 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6106 | LocationSummary::kCallOnSlowPath : |
| 6107 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6108 | break; |
| 6109 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6110 | case TypeCheckKind::kUnresolvedCheck: |
| 6111 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6112 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6113 | break; |
| 6114 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6115 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6116 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6117 | locations->SetInAt(1, Location::Any()); |
| 6118 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6119 | locations->AddTemp(Location::RequiresRegister()); |
| 6120 | // When read barriers are enabled, we need an additional temporary |
| 6121 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6122 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6123 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6124 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
| 6127 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6128 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6129 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6130 | Location obj_loc = locations->InAt(0); |
| 6131 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6132 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6133 | Location temp_loc = locations->GetTemp(0); |
| 6134 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6135 | Location temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
| 6136 | locations->GetTemp(1) : |
| 6137 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6138 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6139 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6140 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6141 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6142 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6143 | bool is_type_check_slow_path_fatal = |
| 6144 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6145 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6146 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6147 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6148 | !instruction->CanThrowIntoCatchBlock(); |
| 6149 | SlowPathCode* type_check_slow_path = |
| 6150 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6151 | is_type_check_slow_path_fatal); |
| 6152 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6153 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6154 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6155 | // Avoid null check if we know obj is not null. |
| 6156 | if (instruction->MustDoNullCheck()) { |
| 6157 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6158 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6159 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6160 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6161 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6162 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6163 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6164 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6165 | case TypeCheckKind::kExactCheck: |
| 6166 | case TypeCheckKind::kArrayCheck: { |
| 6167 | if (cls.IsRegister()) { |
| 6168 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6169 | } else { |
| 6170 | DCHECK(cls.IsStackSlot()) << cls; |
| 6171 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6172 | } |
| 6173 | // Jump to slow path for throwing the exception or doing a |
| 6174 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6175 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6176 | break; |
| 6177 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6178 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6179 | case TypeCheckKind::kAbstractClassCheck: { |
| 6180 | // If the class is abstract, we eagerly fetch the super class of the |
| 6181 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6182 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6183 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6184 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6185 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6186 | |
| 6187 | // If the class reference currently in `temp` is not null, jump |
| 6188 | // to the `compare_classes` label to compare it with the checked |
| 6189 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6190 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6191 | __ j(kNotEqual, &compare_classes); |
| 6192 | // Otherwise, jump to the slow path to throw the exception. |
| 6193 | // |
| 6194 | // But before, move back the object's class into `temp` before |
| 6195 | // going into the slow path, as it has been overwritten in the |
| 6196 | // meantime. |
| 6197 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6198 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6199 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6200 | |
| 6201 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6202 | if (cls.IsRegister()) { |
| 6203 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6204 | } else { |
| 6205 | DCHECK(cls.IsStackSlot()) << cls; |
| 6206 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6207 | } |
| 6208 | __ j(kNotEqual, &loop); |
| 6209 | break; |
| 6210 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6211 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6212 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6213 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6214 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6215 | __ Bind(&loop); |
| 6216 | if (cls.IsRegister()) { |
| 6217 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6218 | } else { |
| 6219 | DCHECK(cls.IsStackSlot()) << cls; |
| 6220 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6221 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6222 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6223 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6224 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6225 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6226 | |
| 6227 | // If the class reference currently in `temp` is not null, jump |
| 6228 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6229 | __ testl(temp, temp); |
| 6230 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6231 | // Otherwise, jump to the slow path to throw the exception. |
| 6232 | // |
| 6233 | // But before, move back the object's class into `temp` before |
| 6234 | // going into the slow path, as it has been overwritten in the |
| 6235 | // meantime. |
| 6236 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6237 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6238 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6239 | break; |
| 6240 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6241 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6242 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6243 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6244 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6245 | if (cls.IsRegister()) { |
| 6246 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6247 | } else { |
| 6248 | DCHECK(cls.IsStackSlot()) << cls; |
| 6249 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6250 | } |
| 6251 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6252 | |
| 6253 | // 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] | 6254 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6255 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6256 | |
| 6257 | // If the component type is not null (i.e. the object is indeed |
| 6258 | // an array), jump to label `check_non_primitive_component_type` |
| 6259 | // to further check that this component type is not a primitive |
| 6260 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6261 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6262 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6263 | // Otherwise, jump to the slow path to throw the exception. |
| 6264 | // |
| 6265 | // But before, move back the object's class into `temp` before |
| 6266 | // going into the slow path, as it has been overwritten in the |
| 6267 | // meantime. |
| 6268 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6269 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6270 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6271 | |
| 6272 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6273 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6274 | __ j(kEqual, &done); |
| 6275 | // Same comment as above regarding `temp` and the slow path. |
| 6276 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6277 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6278 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6279 | break; |
| 6280 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6281 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6282 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6283 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6284 | // We always go into the type check slow path for the unresolved & |
| 6285 | // interface check cases. |
| 6286 | // |
| 6287 | // We cannot directly call the CheckCast runtime entry point |
| 6288 | // without resorting to a type checking slow path here (i.e. by |
| 6289 | // calling InvokeRuntime directly), as it would require to |
| 6290 | // assign fixed registers for the inputs of this HInstanceOf |
| 6291 | // instruction (following the runtime calling convention), which |
| 6292 | // might be cluttered by the potential first read barrier |
| 6293 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6294 | // |
| 6295 | // TODO: Introduce a new runtime entry point taking the object |
| 6296 | // to test (instead of its class) as argument, and let it deal |
| 6297 | // with the read barrier issues. This will let us refactor this |
| 6298 | // case of the `switch` code as it was previously (with a direct |
| 6299 | // call to the runtime not using a type checking slow path). |
| 6300 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6301 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6302 | break; |
| 6303 | } |
| 6304 | __ Bind(&done); |
| 6305 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6306 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6307 | } |
| 6308 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6309 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6310 | LocationSummary* locations = |
| 6311 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6312 | InvokeRuntimeCallingConvention calling_convention; |
| 6313 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6314 | } |
| 6315 | |
| 6316 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6317 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6318 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6319 | instruction, |
| 6320 | instruction->GetDexPc(), |
| 6321 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6322 | if (instruction->IsEnter()) { |
| 6323 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6324 | } else { |
| 6325 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6326 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6327 | } |
| 6328 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6329 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6330 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6331 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6332 | |
| 6333 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6334 | LocationSummary* locations = |
| 6335 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6336 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6337 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6338 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6339 | locations->SetInAt(1, Location::Any()); |
| 6340 | locations->SetOut(Location::SameAsFirstInput()); |
| 6341 | } |
| 6342 | |
| 6343 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6344 | HandleBitwiseOperation(instruction); |
| 6345 | } |
| 6346 | |
| 6347 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6348 | HandleBitwiseOperation(instruction); |
| 6349 | } |
| 6350 | |
| 6351 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6352 | HandleBitwiseOperation(instruction); |
| 6353 | } |
| 6354 | |
| 6355 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6356 | LocationSummary* locations = instruction->GetLocations(); |
| 6357 | Location first = locations->InAt(0); |
| 6358 | Location second = locations->InAt(1); |
| 6359 | DCHECK(first.Equals(locations->Out())); |
| 6360 | |
| 6361 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6362 | if (second.IsRegister()) { |
| 6363 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6364 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6365 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6366 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6367 | } else { |
| 6368 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6369 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6370 | } |
| 6371 | } else if (second.IsConstant()) { |
| 6372 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6373 | __ andl(first.AsRegister<Register>(), |
| 6374 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6375 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6376 | __ orl(first.AsRegister<Register>(), |
| 6377 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6378 | } else { |
| 6379 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6380 | __ xorl(first.AsRegister<Register>(), |
| 6381 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6382 | } |
| 6383 | } else { |
| 6384 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6385 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6386 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6387 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6388 | } else { |
| 6389 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6390 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6391 | } |
| 6392 | } |
| 6393 | } else { |
| 6394 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6395 | if (second.IsRegisterPair()) { |
| 6396 | if (instruction->IsAnd()) { |
| 6397 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6398 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6399 | } else if (instruction->IsOr()) { |
| 6400 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6401 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6402 | } else { |
| 6403 | DCHECK(instruction->IsXor()); |
| 6404 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6405 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6406 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6407 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6408 | if (instruction->IsAnd()) { |
| 6409 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6410 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6411 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6412 | } else if (instruction->IsOr()) { |
| 6413 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6414 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6415 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6416 | } else { |
| 6417 | DCHECK(instruction->IsXor()); |
| 6418 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6419 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6420 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6421 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6422 | } else { |
| 6423 | DCHECK(second.IsConstant()) << second; |
| 6424 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6425 | int32_t low_value = Low32Bits(value); |
| 6426 | int32_t high_value = High32Bits(value); |
| 6427 | Immediate low(low_value); |
| 6428 | Immediate high(high_value); |
| 6429 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6430 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6431 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6432 | if (low_value == 0) { |
| 6433 | __ xorl(first_low, first_low); |
| 6434 | } else if (low_value != -1) { |
| 6435 | __ andl(first_low, low); |
| 6436 | } |
| 6437 | if (high_value == 0) { |
| 6438 | __ xorl(first_high, first_high); |
| 6439 | } else if (high_value != -1) { |
| 6440 | __ andl(first_high, high); |
| 6441 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6442 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6443 | if (low_value != 0) { |
| 6444 | __ orl(first_low, low); |
| 6445 | } |
| 6446 | if (high_value != 0) { |
| 6447 | __ orl(first_high, high); |
| 6448 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6449 | } else { |
| 6450 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6451 | if (low_value != 0) { |
| 6452 | __ xorl(first_low, low); |
| 6453 | } |
| 6454 | if (high_value != 0) { |
| 6455 | __ xorl(first_high, high); |
| 6456 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6457 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6458 | } |
| 6459 | } |
| 6460 | } |
| 6461 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6462 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6463 | Location out, |
| 6464 | uint32_t offset, |
| 6465 | Location temp) { |
| 6466 | Register out_reg = out.AsRegister<Register>(); |
| 6467 | if (kEmitCompilerReadBarrier) { |
| 6468 | if (kUseBakerReadBarrier) { |
| 6469 | // Load with fast path based Baker's read barrier. |
| 6470 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6471 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 6472 | instruction, out, out_reg, offset, temp, /* needs_null_check */ false); |
| 6473 | } else { |
| 6474 | // Load with slow path based read barrier. |
| 6475 | // Save the value of `out` into `temp` before overwriting it |
| 6476 | // in the following move operation, as we will need it for the |
| 6477 | // read barrier below. |
| 6478 | __ movl(temp.AsRegister<Register>(), out_reg); |
| 6479 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6480 | __ movl(out_reg, Address(out_reg, offset)); |
| 6481 | codegen_->GenerateReadBarrierSlow(instruction, out, out, temp, offset); |
| 6482 | } |
| 6483 | } else { |
| 6484 | // Plain load with no read barrier. |
| 6485 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6486 | __ movl(out_reg, Address(out_reg, offset)); |
| 6487 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6488 | } |
| 6489 | } |
| 6490 | |
| 6491 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6492 | Location out, |
| 6493 | Location obj, |
| 6494 | uint32_t offset, |
| 6495 | Location temp) { |
| 6496 | Register out_reg = out.AsRegister<Register>(); |
| 6497 | Register obj_reg = obj.AsRegister<Register>(); |
| 6498 | if (kEmitCompilerReadBarrier) { |
| 6499 | if (kUseBakerReadBarrier) { |
| 6500 | // Load with fast path based Baker's read barrier. |
| 6501 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6502 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 6503 | instruction, out, obj_reg, offset, temp, /* needs_null_check */ false); |
| 6504 | } else { |
| 6505 | // Load with slow path based read barrier. |
| 6506 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6507 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6508 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6509 | } |
| 6510 | } else { |
| 6511 | // Plain load with no read barrier. |
| 6512 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6513 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6514 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6519 | Location root, |
| 6520 | Register obj, |
| 6521 | uint32_t offset) { |
| 6522 | Register root_reg = root.AsRegister<Register>(); |
| 6523 | if (kEmitCompilerReadBarrier) { |
| 6524 | if (kUseBakerReadBarrier) { |
| 6525 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6526 | // Baker's read barrier are used: |
| 6527 | // |
| 6528 | // root = obj.field; |
| 6529 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6530 | // root = ReadBarrier::Mark(root) |
| 6531 | // } |
| 6532 | |
| 6533 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6534 | __ movl(root_reg, Address(obj, offset)); |
| 6535 | static_assert( |
| 6536 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6537 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6538 | "have different sizes."); |
| 6539 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6540 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6541 | "have different sizes."); |
| 6542 | |
| 6543 | // Slow path used to mark the GC root `root`. |
| 6544 | SlowPathCode* slow_path = |
| 6545 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6546 | codegen_->AddSlowPath(slow_path); |
| 6547 | |
| 6548 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6549 | Immediate(0)); |
| 6550 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6551 | __ Bind(slow_path->GetExitLabel()); |
| 6552 | } else { |
| 6553 | // GC root loaded through a slow path for read barriers other |
| 6554 | // than Baker's. |
| 6555 | // /* GcRoot<mirror::Object>* */ root = obj + offset |
| 6556 | __ leal(root_reg, Address(obj, offset)); |
| 6557 | // /* mirror::Object* */ root = root->Read() |
| 6558 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6559 | } |
| 6560 | } else { |
| 6561 | // Plain GC root load with no read barrier. |
| 6562 | // /* GcRoot<mirror::Object> */ root = *(obj + offset) |
| 6563 | __ movl(root_reg, Address(obj, offset)); |
| 6564 | } |
| 6565 | } |
| 6566 | |
| 6567 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6568 | Location ref, |
| 6569 | Register obj, |
| 6570 | uint32_t offset, |
| 6571 | Location temp, |
| 6572 | bool needs_null_check) { |
| 6573 | DCHECK(kEmitCompilerReadBarrier); |
| 6574 | DCHECK(kUseBakerReadBarrier); |
| 6575 | |
| 6576 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6577 | Address src(obj, offset); |
| 6578 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6579 | } |
| 6580 | |
| 6581 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6582 | Location ref, |
| 6583 | Register obj, |
| 6584 | uint32_t data_offset, |
| 6585 | Location index, |
| 6586 | Location temp, |
| 6587 | bool needs_null_check) { |
| 6588 | DCHECK(kEmitCompilerReadBarrier); |
| 6589 | DCHECK(kUseBakerReadBarrier); |
| 6590 | |
| 6591 | // /* HeapReference<Object> */ ref = |
| 6592 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6593 | Address src = index.IsConstant() ? |
| 6594 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6595 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6596 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6597 | } |
| 6598 | |
| 6599 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6600 | Location ref, |
| 6601 | Register obj, |
| 6602 | const Address& src, |
| 6603 | Location temp, |
| 6604 | bool needs_null_check) { |
| 6605 | DCHECK(kEmitCompilerReadBarrier); |
| 6606 | DCHECK(kUseBakerReadBarrier); |
| 6607 | |
| 6608 | // In slow path based read barriers, the read barrier call is |
| 6609 | // inserted after the original load. However, in fast path based |
| 6610 | // Baker's read barriers, we need to perform the load of |
| 6611 | // mirror::Object::monitor_ *before* the original reference load. |
| 6612 | // This load-load ordering is required by the read barrier. |
| 6613 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6614 | // |
| 6615 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6616 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6617 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6618 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6619 | // if (is_gray) { |
| 6620 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6621 | // } |
| 6622 | // |
| 6623 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6624 | // slightly more complex as: |
| 6625 | // - it implements the load-load fence using a data dependency on |
| 6626 | // the high-bits of rb_state, which are expected to be all zeroes; |
| 6627 | // - it performs additional checks that we do not do here for |
| 6628 | // performance reasons. |
| 6629 | |
| 6630 | Register ref_reg = ref.AsRegister<Register>(); |
| 6631 | Register temp_reg = temp.AsRegister<Register>(); |
| 6632 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6633 | |
| 6634 | // /* int32_t */ monitor = obj->monitor_ |
| 6635 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6636 | if (needs_null_check) { |
| 6637 | MaybeRecordImplicitNullCheck(instruction); |
| 6638 | } |
| 6639 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6640 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6641 | "art::LockWord and int32_t have different sizes."); |
| 6642 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6643 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6644 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6645 | static_assert( |
| 6646 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6647 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6648 | |
| 6649 | // Load fence to prevent load-load reordering. |
| 6650 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6651 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6652 | |
| 6653 | // The actual reference load. |
| 6654 | // /* HeapReference<Object> */ ref = *src |
| 6655 | __ movl(ref_reg, src); |
| 6656 | |
| 6657 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6658 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6659 | |
| 6660 | // Slow path used to mark the object `ref` when it is gray. |
| 6661 | SlowPathCode* slow_path = |
| 6662 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6663 | AddSlowPath(slow_path); |
| 6664 | |
| 6665 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6666 | // ref = ReadBarrier::Mark(ref); |
| 6667 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6668 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6669 | __ Bind(slow_path->GetExitLabel()); |
| 6670 | } |
| 6671 | |
| 6672 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6673 | Location out, |
| 6674 | Location ref, |
| 6675 | Location obj, |
| 6676 | uint32_t offset, |
| 6677 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6678 | DCHECK(kEmitCompilerReadBarrier); |
| 6679 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6680 | // Insert a slow path based read barrier *after* the reference load. |
| 6681 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6682 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6683 | // reference will be carried out by the runtime within the slow |
| 6684 | // path. |
| 6685 | // |
| 6686 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6687 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6688 | // not used by the artReadBarrierSlow entry point. |
| 6689 | // |
| 6690 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6691 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6692 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6693 | AddSlowPath(slow_path); |
| 6694 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6695 | __ jmp(slow_path->GetEntryLabel()); |
| 6696 | __ Bind(slow_path->GetExitLabel()); |
| 6697 | } |
| 6698 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6699 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6700 | Location out, |
| 6701 | Location ref, |
| 6702 | Location obj, |
| 6703 | uint32_t offset, |
| 6704 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6705 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6706 | // Baker's read barriers shall be handled by the fast path |
| 6707 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6708 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6709 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6710 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6711 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6712 | } else if (kPoisonHeapReferences) { |
| 6713 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6714 | } |
| 6715 | } |
| 6716 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6717 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6718 | Location out, |
| 6719 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6720 | DCHECK(kEmitCompilerReadBarrier); |
| 6721 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6722 | // Insert a slow path based read barrier *after* the GC root load. |
| 6723 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6724 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6725 | // not need to do anything special for this here. |
| 6726 | SlowPathCode* slow_path = |
| 6727 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6728 | AddSlowPath(slow_path); |
| 6729 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6730 | __ jmp(slow_path->GetEntryLabel()); |
| 6731 | __ Bind(slow_path->GetExitLabel()); |
| 6732 | } |
| 6733 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6734 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6735 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6736 | LOG(FATAL) << "Unreachable"; |
| 6737 | } |
| 6738 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6739 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6740 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6741 | LOG(FATAL) << "Unreachable"; |
| 6742 | } |
| 6743 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 6744 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 6745 | DCHECK(codegen_->IsBaseline()); |
| 6746 | LocationSummary* locations = |
| 6747 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6748 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 6749 | } |
| 6750 | |
| 6751 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 6752 | DCHECK(codegen_->IsBaseline()); |
| 6753 | // Will be generated at use site. |
| 6754 | } |
| 6755 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6756 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 6757 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6758 | LocationSummary* locations = |
| 6759 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6760 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6761 | } |
| 6762 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6763 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 6764 | int32_t lower_bound, |
| 6765 | uint32_t num_entries, |
| 6766 | HBasicBlock* switch_block, |
| 6767 | HBasicBlock* default_block) { |
| 6768 | // Figure out the correct compare values and jump conditions. |
| 6769 | // Handle the first compare/branch as a special case because it might |
| 6770 | // jump to the default case. |
| 6771 | DCHECK_GT(num_entries, 2u); |
| 6772 | Condition first_condition; |
| 6773 | uint32_t index; |
| 6774 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 6775 | if (lower_bound != 0) { |
| 6776 | first_condition = kLess; |
| 6777 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 6778 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 6779 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6780 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6781 | index = 1; |
| 6782 | } else { |
| 6783 | // Handle all the compare/jumps below. |
| 6784 | first_condition = kBelow; |
| 6785 | index = 0; |
| 6786 | } |
| 6787 | |
| 6788 | // Handle the rest of the compare/jumps. |
| 6789 | for (; index + 1 < num_entries; index += 2) { |
| 6790 | int32_t compare_to_value = lower_bound + index + 1; |
| 6791 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 6792 | // Jump to successors[index] if value < case_value[index]. |
| 6793 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 6794 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 6795 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 6796 | } |
| 6797 | |
| 6798 | if (index != num_entries) { |
| 6799 | // There are an odd number of entries. Handle the last one. |
| 6800 | DCHECK_EQ(index + 1, num_entries); |
| 6801 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 6802 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6803 | } |
| 6804 | |
| 6805 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6806 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 6807 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 6808 | } |
| 6809 | } |
| 6810 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6811 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 6812 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 6813 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 6814 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6815 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6816 | |
| 6817 | GenPackedSwitchWithCompares(value_reg, |
| 6818 | lower_bound, |
| 6819 | num_entries, |
| 6820 | switch_instr->GetBlock(), |
| 6821 | switch_instr->GetDefaultBlock()); |
| 6822 | } |
| 6823 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6824 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6825 | LocationSummary* locations = |
| 6826 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 6827 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6828 | |
| 6829 | // Constant area pointer. |
| 6830 | locations->SetInAt(1, Location::RequiresRegister()); |
| 6831 | |
| 6832 | // And the temporary we need. |
| 6833 | locations->AddTemp(Location::RequiresRegister()); |
| 6834 | } |
| 6835 | |
| 6836 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 6837 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6838 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6839 | LocationSummary* locations = switch_instr->GetLocations(); |
| 6840 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 6841 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 6842 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6843 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 6844 | GenPackedSwitchWithCompares(value_reg, |
| 6845 | lower_bound, |
| 6846 | num_entries, |
| 6847 | switch_instr->GetBlock(), |
| 6848 | default_block); |
| 6849 | return; |
| 6850 | } |
| 6851 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6852 | // Optimizing has a jump area. |
| 6853 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 6854 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 6855 | |
| 6856 | // Remove the bias, if needed. |
| 6857 | if (lower_bound != 0) { |
| 6858 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 6859 | value_reg = temp_reg; |
| 6860 | } |
| 6861 | |
| 6862 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 6863 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6864 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 6865 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 6866 | |
| 6867 | // We are in the range of the table. |
| 6868 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 6869 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 6870 | |
| 6871 | // Compute the actual target address by adding in constant_area. |
| 6872 | __ addl(temp_reg, constant_area); |
| 6873 | |
| 6874 | // And jump. |
| 6875 | __ jmp(temp_reg); |
| 6876 | } |
| 6877 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6878 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 6879 | HX86ComputeBaseMethodAddress* insn) { |
| 6880 | LocationSummary* locations = |
| 6881 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6882 | locations->SetOut(Location::RequiresRegister()); |
| 6883 | } |
| 6884 | |
| 6885 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 6886 | HX86ComputeBaseMethodAddress* insn) { |
| 6887 | LocationSummary* locations = insn->GetLocations(); |
| 6888 | Register reg = locations->Out().AsRegister<Register>(); |
| 6889 | |
| 6890 | // Generate call to next instruction. |
| 6891 | Label next_instruction; |
| 6892 | __ call(&next_instruction); |
| 6893 | __ Bind(&next_instruction); |
| 6894 | |
| 6895 | // Remember this offset for later use with constant area. |
| 6896 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 6897 | |
| 6898 | // Grab the return address off the stack. |
| 6899 | __ popl(reg); |
| 6900 | } |
| 6901 | |
| 6902 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 6903 | HX86LoadFromConstantTable* insn) { |
| 6904 | LocationSummary* locations = |
| 6905 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 6906 | |
| 6907 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6908 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 6909 | |
| 6910 | // If we don't need to be materialized, we only need the inputs to be set. |
| 6911 | if (!insn->NeedsMaterialization()) { |
| 6912 | return; |
| 6913 | } |
| 6914 | |
| 6915 | switch (insn->GetType()) { |
| 6916 | case Primitive::kPrimFloat: |
| 6917 | case Primitive::kPrimDouble: |
| 6918 | locations->SetOut(Location::RequiresFpuRegister()); |
| 6919 | break; |
| 6920 | |
| 6921 | case Primitive::kPrimInt: |
| 6922 | locations->SetOut(Location::RequiresRegister()); |
| 6923 | break; |
| 6924 | |
| 6925 | default: |
| 6926 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6927 | } |
| 6928 | } |
| 6929 | |
| 6930 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 6931 | if (!insn->NeedsMaterialization()) { |
| 6932 | return; |
| 6933 | } |
| 6934 | |
| 6935 | LocationSummary* locations = insn->GetLocations(); |
| 6936 | Location out = locations->Out(); |
| 6937 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 6938 | HConstant *value = insn->GetConstant(); |
| 6939 | |
| 6940 | switch (insn->GetType()) { |
| 6941 | case Primitive::kPrimFloat: |
| 6942 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 6943 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 6944 | break; |
| 6945 | |
| 6946 | case Primitive::kPrimDouble: |
| 6947 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 6948 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 6949 | break; |
| 6950 | |
| 6951 | case Primitive::kPrimInt: |
| 6952 | __ movl(out.AsRegister<Register>(), |
| 6953 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 6954 | break; |
| 6955 | |
| 6956 | default: |
| 6957 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 6958 | } |
| 6959 | } |
| 6960 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6961 | /** |
| 6962 | * Class to handle late fixup of offsets into constant area. |
| 6963 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 6964 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6965 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6966 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 6967 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 6968 | |
| 6969 | protected: |
| 6970 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 6971 | |
| 6972 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6973 | |
| 6974 | private: |
| 6975 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 6976 | // Patch the correct offset for the instruction. The place to patch is the |
| 6977 | // last 4 bytes of the instruction. |
| 6978 | // The value to patch is the distance from the offset in the constant area |
| 6979 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6980 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 6981 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6982 | |
| 6983 | // Patch in the right value. |
| 6984 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 6985 | } |
| 6986 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6987 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6988 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6989 | }; |
| 6990 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 6991 | /** |
| 6992 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 6993 | * constant area. |
| 6994 | */ |
| 6995 | class JumpTableRIPFixup : public RIPFixup { |
| 6996 | public: |
| 6997 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 6998 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 6999 | |
| 7000 | void CreateJumpTable() { |
| 7001 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7002 | |
| 7003 | // Ensure that the reference to the jump table has the correct offset. |
| 7004 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7005 | SetOffset(offset_in_constant_table); |
| 7006 | |
| 7007 | // The label values in the jump table are computed relative to the |
| 7008 | // instruction addressing the constant area. |
| 7009 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7010 | |
| 7011 | // Populate the jump table with the correct values for the jump table. |
| 7012 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7013 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7014 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7015 | // The value that we want is the target offset - the position of the table. |
| 7016 | for (int32_t i = 0; i < num_entries; i++) { |
| 7017 | HBasicBlock* b = successors[i]; |
| 7018 | Label* l = codegen_->GetLabelOf(b); |
| 7019 | DCHECK(l->IsBound()); |
| 7020 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7021 | assembler->AppendInt32(offset_to_block); |
| 7022 | } |
| 7023 | } |
| 7024 | |
| 7025 | private: |
| 7026 | const HX86PackedSwitch* switch_instr_; |
| 7027 | }; |
| 7028 | |
| 7029 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7030 | // Generate the constant area if needed. |
| 7031 | X86Assembler* assembler = GetAssembler(); |
| 7032 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7033 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7034 | // byte values. |
| 7035 | assembler->Align(4, 0); |
| 7036 | constant_area_start_ = assembler->CodeSize(); |
| 7037 | |
| 7038 | // Populate any jump tables. |
| 7039 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7040 | jump_table->CreateJumpTable(); |
| 7041 | } |
| 7042 | |
| 7043 | // And now add the constant area to the generated code. |
| 7044 | assembler->AddConstantArea(); |
| 7045 | } |
| 7046 | |
| 7047 | // And finish up. |
| 7048 | CodeGenerator::Finalize(allocator); |
| 7049 | } |
| 7050 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7051 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7052 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7053 | return Address(reg, kDummy32BitOffset, fixup); |
| 7054 | } |
| 7055 | |
| 7056 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7057 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7058 | return Address(reg, kDummy32BitOffset, fixup); |
| 7059 | } |
| 7060 | |
| 7061 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7062 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7063 | return Address(reg, kDummy32BitOffset, fixup); |
| 7064 | } |
| 7065 | |
| 7066 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7067 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7068 | return Address(reg, kDummy32BitOffset, fixup); |
| 7069 | } |
| 7070 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7071 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7072 | Register reg, |
| 7073 | Register value) { |
| 7074 | // Create a fixup to be used to create and address the jump table. |
| 7075 | JumpTableRIPFixup* table_fixup = |
| 7076 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7077 | |
| 7078 | // We have to populate the jump tables. |
| 7079 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7080 | |
| 7081 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7082 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7083 | } |
| 7084 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7085 | // TODO: target as memory. |
| 7086 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7087 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7088 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7089 | return; |
| 7090 | } |
| 7091 | |
| 7092 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7093 | |
| 7094 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7095 | if (target.Equals(return_loc)) { |
| 7096 | return; |
| 7097 | } |
| 7098 | |
| 7099 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7100 | // with the else branch. |
| 7101 | if (type == Primitive::kPrimLong) { |
| 7102 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7103 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7104 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7105 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7106 | } else { |
| 7107 | // Let the parallel move resolver take care of all of this. |
| 7108 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7109 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7110 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7111 | } |
| 7112 | } |
| 7113 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7114 | #undef __ |
| 7115 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7116 | } // namespace x86 |
| 7117 | } // namespace art |