Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 18 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 19 | #include "art_method.h" |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 20 | #include "code_generator_utils.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 21 | #include "compiled_method.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 24 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 25 | #include "intrinsics.h" |
| 26 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 27 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 29 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 30 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 31 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 33 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 34 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 36 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 37 | template<class MirrorType> |
| 38 | class GcRoot; |
| 39 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace x86 { |
| 41 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | static constexpr Register kMethodRegisterArgument = EAX; |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 44 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 45 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 46 | static constexpr int kC2ConditionMask = 0x400; |
| 47 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 48 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 49 | |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 50 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 51 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
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: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 56 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(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 | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 78 | }; |
| 79 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 80 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 81 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 82 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 83 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 84 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 85 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 86 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 87 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 88 | // Live registers will be restored in the catch block if caught. |
| 89 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 90 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 91 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 92 | instruction_, |
| 93 | instruction_->GetDexPc(), |
| 94 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 95 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 98 | bool IsFatal() const OVERRIDE { return true; } |
| 99 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 100 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 101 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 102 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 104 | }; |
| 105 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 106 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 108 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) |
| 109 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 110 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 111 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 113 | if (is_div_) { |
| 114 | __ negl(reg_); |
| 115 | } else { |
| 116 | __ movl(reg_, Immediate(0)); |
| 117 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 118 | __ jmp(GetExitLabel()); |
| 119 | } |
| 120 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 121 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 122 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 123 | private: |
| 124 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 125 | bool is_div_; |
| 126 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 129 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 130 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 131 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 132 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 133 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 134 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 135 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 136 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 137 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 138 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 139 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 140 | // Live registers will be restored in the catch block if caught. |
| 141 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 142 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 143 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 144 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 145 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 146 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 147 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 148 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 149 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 150 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 151 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 152 | instruction_, |
| 153 | instruction_->GetDexPc(), |
| 154 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 155 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 158 | bool IsFatal() const OVERRIDE { return true; } |
| 159 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 160 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 161 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 162 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 163 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 164 | }; |
| 165 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 166 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 167 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 168 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 169 | : SlowPathCode(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 170 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 171 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 172 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 173 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 174 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 175 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 176 | instruction_, |
| 177 | instruction_->GetDexPc(), |
| 178 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 179 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 180 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 181 | if (successor_ == nullptr) { |
| 182 | __ jmp(GetReturnLabel()); |
| 183 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 184 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 185 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 188 | Label* GetReturnLabel() { |
| 189 | DCHECK(successor_ == nullptr); |
| 190 | return &return_label_; |
| 191 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 192 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 193 | HBasicBlock* GetSuccessor() const { |
| 194 | return successor_; |
| 195 | } |
| 196 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 197 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 198 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 199 | private: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 200 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 201 | Label return_label_; |
| 202 | |
| 203 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 204 | }; |
| 205 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 206 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 207 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 208 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 209 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 210 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 211 | LocationSummary* locations = instruction_->GetLocations(); |
| 212 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 213 | |
| 214 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 215 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 216 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 217 | |
| 218 | InvokeRuntimeCallingConvention calling_convention; |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 219 | const uint32_t string_index = instruction_->AsLoadString()->GetStringIndex(); |
| 220 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 221 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 222 | instruction_, |
| 223 | instruction_->GetDexPc(), |
| 224 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 225 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 226 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 227 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 228 | |
| 229 | __ jmp(GetExitLabel()); |
| 230 | } |
| 231 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 232 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 233 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 234 | private: |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 235 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 236 | }; |
| 237 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 238 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 239 | public: |
| 240 | LoadClassSlowPathX86(HLoadClass* cls, |
| 241 | HInstruction* at, |
| 242 | uint32_t dex_pc, |
| 243 | bool do_clinit) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 244 | : SlowPathCode(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 245 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 246 | } |
| 247 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 248 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 249 | LocationSummary* locations = at_->GetLocations(); |
| 250 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 251 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 252 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 253 | |
| 254 | InvokeRuntimeCallingConvention calling_convention; |
| 255 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 256 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 257 | : QUICK_ENTRY_POINT(pInitializeType), |
| 258 | at_, dex_pc_, this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 259 | if (do_clinit_) { |
| 260 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>(); |
| 261 | } else { |
| 262 | CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>(); |
| 263 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 264 | |
| 265 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 266 | Location out = locations->Out(); |
| 267 | if (out.IsValid()) { |
| 268 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 269 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 270 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 271 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 272 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 273 | __ jmp(GetExitLabel()); |
| 274 | } |
| 275 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 276 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 277 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 278 | private: |
| 279 | // The class this slow path will load. |
| 280 | HLoadClass* const cls_; |
| 281 | |
| 282 | // The instruction where this slow path is happening. |
| 283 | // (Might be the load class or an initialization check). |
| 284 | HInstruction* const at_; |
| 285 | |
| 286 | // The dex PC of `at_`. |
| 287 | const uint32_t dex_pc_; |
| 288 | |
| 289 | // Whether to initialize the class. |
| 290 | const bool do_clinit_; |
| 291 | |
| 292 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 293 | }; |
| 294 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 295 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 296 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 297 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 298 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 300 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 301 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 302 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 303 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 304 | DCHECK(instruction_->IsCheckCast() |
| 305 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 306 | |
| 307 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 308 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 309 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 310 | if (!is_fatal_) { |
| 311 | SaveLiveRegisters(codegen, locations); |
| 312 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 313 | |
| 314 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 315 | // move resolver. |
| 316 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 317 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 318 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 319 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 320 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 321 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 322 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 323 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 325 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 326 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 327 | instruction_, |
| 328 | instruction_->GetDexPc(), |
| 329 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 330 | CheckEntrypointTypes< |
| 331 | kQuickInstanceofNonTrivial, uint32_t, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 332 | } else { |
| 333 | DCHECK(instruction_->IsCheckCast()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 334 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 335 | instruction_, |
| 336 | instruction_->GetDexPc(), |
| 337 | this); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 338 | CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 341 | if (!is_fatal_) { |
| 342 | if (instruction_->IsInstanceOf()) { |
| 343 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 344 | } |
| 345 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 346 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 347 | __ jmp(GetExitLabel()); |
| 348 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 351 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 352 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 353 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 354 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 355 | const bool is_fatal_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 356 | |
| 357 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); |
| 358 | }; |
| 359 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 360 | class DeoptimizationSlowPathX86 : public SlowPathCode { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 361 | public: |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 362 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 363 | : SlowPathCode(instruction) {} |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 364 | |
| 365 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 366 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 367 | __ Bind(GetEntryLabel()); |
| 368 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 369 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 370 | instruction_, |
| 371 | instruction_->GetDexPc(), |
| 372 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 373 | CheckEntrypointTypes<kQuickDeoptimize, void, void>(); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 376 | const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathX86"; } |
| 377 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 378 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 379 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 380 | }; |
| 381 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 382 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 383 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 384 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 385 | |
| 386 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 387 | LocationSummary* locations = instruction_->GetLocations(); |
| 388 | __ Bind(GetEntryLabel()); |
| 389 | SaveLiveRegisters(codegen, locations); |
| 390 | |
| 391 | InvokeRuntimeCallingConvention calling_convention; |
| 392 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 393 | parallel_move.AddMove( |
| 394 | locations->InAt(0), |
| 395 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 396 | Primitive::kPrimNot, |
| 397 | nullptr); |
| 398 | parallel_move.AddMove( |
| 399 | locations->InAt(1), |
| 400 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 401 | Primitive::kPrimInt, |
| 402 | nullptr); |
| 403 | parallel_move.AddMove( |
| 404 | locations->InAt(2), |
| 405 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 406 | Primitive::kPrimNot, |
| 407 | nullptr); |
| 408 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 409 | |
| 410 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 411 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 412 | instruction_, |
| 413 | instruction_->GetDexPc(), |
| 414 | this); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 415 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 416 | RestoreLiveRegisters(codegen, locations); |
| 417 | __ jmp(GetExitLabel()); |
| 418 | } |
| 419 | |
| 420 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 421 | |
| 422 | private: |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 423 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 424 | }; |
| 425 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 426 | // Slow path marking an object during a read barrier. |
| 427 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { |
| 428 | public: |
| 429 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, Location out, Location obj) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 430 | : SlowPathCode(instruction), out_(out), obj_(obj) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 431 | DCHECK(kEmitCompilerReadBarrier); |
| 432 | } |
| 433 | |
| 434 | const char* GetDescription() const OVERRIDE { return "ReadBarrierMarkSlowPathX86"; } |
| 435 | |
| 436 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 437 | LocationSummary* locations = instruction_->GetLocations(); |
| 438 | Register reg_out = out_.AsRegister<Register>(); |
| 439 | DCHECK(locations->CanCall()); |
| 440 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 441 | DCHECK(instruction_->IsInstanceFieldGet() || |
| 442 | instruction_->IsStaticFieldGet() || |
| 443 | instruction_->IsArrayGet() || |
| 444 | instruction_->IsLoadClass() || |
| 445 | instruction_->IsLoadString() || |
| 446 | instruction_->IsInstanceOf() || |
| 447 | instruction_->IsCheckCast()) |
| 448 | << "Unexpected instruction in read barrier marking slow path: " |
| 449 | << instruction_->DebugName(); |
| 450 | |
| 451 | __ Bind(GetEntryLabel()); |
| 452 | SaveLiveRegisters(codegen, locations); |
| 453 | |
| 454 | InvokeRuntimeCallingConvention calling_convention; |
| 455 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 456 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), obj_); |
| 457 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierMark), |
| 458 | instruction_, |
| 459 | instruction_->GetDexPc(), |
| 460 | this); |
| 461 | CheckEntrypointTypes<kQuickReadBarrierMark, mirror::Object*, mirror::Object*>(); |
| 462 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 463 | |
| 464 | RestoreLiveRegisters(codegen, locations); |
| 465 | __ jmp(GetExitLabel()); |
| 466 | } |
| 467 | |
| 468 | private: |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 469 | const Location out_; |
| 470 | const Location obj_; |
| 471 | |
| 472 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); |
| 473 | }; |
| 474 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 475 | // Slow path generating a read barrier for a heap reference. |
| 476 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { |
| 477 | public: |
| 478 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, |
| 479 | Location out, |
| 480 | Location ref, |
| 481 | Location obj, |
| 482 | uint32_t offset, |
| 483 | Location index) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 484 | : SlowPathCode(instruction), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 485 | out_(out), |
| 486 | ref_(ref), |
| 487 | obj_(obj), |
| 488 | offset_(offset), |
| 489 | index_(index) { |
| 490 | DCHECK(kEmitCompilerReadBarrier); |
| 491 | // If `obj` is equal to `out` or `ref`, it means the initial object |
| 492 | // has been overwritten by (or after) the heap object reference load |
| 493 | // to be instrumented, e.g.: |
| 494 | // |
| 495 | // __ movl(out, Address(out, offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 496 | // codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 497 | // |
| 498 | // In that case, we have lost the information about the original |
| 499 | // object, and the emitted read barrier cannot work properly. |
| 500 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; |
| 501 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; |
| 502 | } |
| 503 | |
| 504 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 505 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 506 | LocationSummary* locations = instruction_->GetLocations(); |
| 507 | Register reg_out = out_.AsRegister<Register>(); |
| 508 | DCHECK(locations->CanCall()); |
| 509 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
| 510 | DCHECK(!instruction_->IsInvoke() || |
| 511 | (instruction_->IsInvokeStaticOrDirect() && |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 512 | instruction_->GetLocations()->Intrinsified())) |
| 513 | << "Unexpected instruction in read barrier for heap reference slow path: " |
| 514 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 515 | |
| 516 | __ Bind(GetEntryLabel()); |
| 517 | SaveLiveRegisters(codegen, locations); |
| 518 | |
| 519 | // We may have to change the index's value, but as `index_` is a |
| 520 | // constant member (like other "inputs" of this slow path), |
| 521 | // introduce a copy of it, `index`. |
| 522 | Location index = index_; |
| 523 | if (index_.IsValid()) { |
| 524 | // Handle `index_` for HArrayGet and intrinsic UnsafeGetObject. |
| 525 | if (instruction_->IsArrayGet()) { |
| 526 | // Compute the actual memory offset and store it in `index`. |
| 527 | Register index_reg = index_.AsRegister<Register>(); |
| 528 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); |
| 529 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { |
| 530 | // We are about to change the value of `index_reg` (see the |
| 531 | // calls to art::x86::X86Assembler::shll and |
| 532 | // art::x86::X86Assembler::AddImmediate below), but it has |
| 533 | // not been saved by the previous call to |
| 534 | // art::SlowPathCode::SaveLiveRegisters, as it is a |
| 535 | // callee-save register -- |
| 536 | // art::SlowPathCode::SaveLiveRegisters does not consider |
| 537 | // callee-save registers, as it has been designed with the |
| 538 | // assumption that callee-save registers are supposed to be |
| 539 | // handled by the called function. So, as a callee-save |
| 540 | // register, `index_reg` _would_ eventually be saved onto |
| 541 | // the stack, but it would be too late: we would have |
| 542 | // changed its value earlier. Therefore, we manually save |
| 543 | // it here into another freely available register, |
| 544 | // `free_reg`, chosen of course among the caller-save |
| 545 | // registers (as a callee-save `free_reg` register would |
| 546 | // exhibit the same problem). |
| 547 | // |
| 548 | // Note we could have requested a temporary register from |
| 549 | // the register allocator instead; but we prefer not to, as |
| 550 | // this is a slow path, and we know we can find a |
| 551 | // caller-save register that is available. |
| 552 | Register free_reg = FindAvailableCallerSaveRegister(codegen); |
| 553 | __ movl(free_reg, index_reg); |
| 554 | index_reg = free_reg; |
| 555 | index = Location::RegisterLocation(index_reg); |
| 556 | } else { |
| 557 | // The initial register stored in `index_` has already been |
| 558 | // saved in the call to art::SlowPathCode::SaveLiveRegisters |
| 559 | // (as it is not a callee-save register), so we can freely |
| 560 | // use it. |
| 561 | } |
| 562 | // Shifting the index value contained in `index_reg` by the scale |
| 563 | // factor (2) cannot overflow in practice, as the runtime is |
| 564 | // unable to allocate object arrays with a size larger than |
| 565 | // 2^26 - 1 (that is, 2^28 - 4 bytes). |
| 566 | __ shll(index_reg, Immediate(TIMES_4)); |
| 567 | static_assert( |
| 568 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 569 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 570 | __ AddImmediate(index_reg, Immediate(offset_)); |
| 571 | } else { |
| 572 | DCHECK(instruction_->IsInvoke()); |
| 573 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 574 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || |
| 575 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) |
| 576 | << instruction_->AsInvoke()->GetIntrinsic(); |
| 577 | DCHECK_EQ(offset_, 0U); |
| 578 | DCHECK(index_.IsRegisterPair()); |
| 579 | // UnsafeGet's offset location is a register pair, the low |
| 580 | // part contains the correct offset. |
| 581 | index = index_.ToLow(); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | // We're moving two or three locations to locations that could |
| 586 | // overlap, so we need a parallel move resolver. |
| 587 | InvokeRuntimeCallingConvention calling_convention; |
| 588 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 589 | parallel_move.AddMove(ref_, |
| 590 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 591 | Primitive::kPrimNot, |
| 592 | nullptr); |
| 593 | parallel_move.AddMove(obj_, |
| 594 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 595 | Primitive::kPrimNot, |
| 596 | nullptr); |
| 597 | if (index.IsValid()) { |
| 598 | parallel_move.AddMove(index, |
| 599 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 600 | Primitive::kPrimInt, |
| 601 | nullptr); |
| 602 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 603 | } else { |
| 604 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 605 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); |
| 606 | } |
| 607 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierSlow), |
| 608 | instruction_, |
| 609 | instruction_->GetDexPc(), |
| 610 | this); |
| 611 | CheckEntrypointTypes< |
| 612 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); |
| 613 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 614 | |
| 615 | RestoreLiveRegisters(codegen, locations); |
| 616 | __ jmp(GetExitLabel()); |
| 617 | } |
| 618 | |
| 619 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForHeapReferenceSlowPathX86"; } |
| 620 | |
| 621 | private: |
| 622 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { |
| 623 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); |
| 624 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); |
| 625 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { |
| 626 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { |
| 627 | return static_cast<Register>(i); |
| 628 | } |
| 629 | } |
| 630 | // We shall never fail to find a free caller-save register, as |
| 631 | // there are more than two core caller-save registers on x86 |
| 632 | // (meaning it is possible to find one which is different from |
| 633 | // `ref` and `obj`). |
| 634 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); |
| 635 | LOG(FATAL) << "Could not find a free caller-save register"; |
| 636 | UNREACHABLE(); |
| 637 | } |
| 638 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 639 | const Location out_; |
| 640 | const Location ref_; |
| 641 | const Location obj_; |
| 642 | const uint32_t offset_; |
| 643 | // An additional location containing an index to an array. |
| 644 | // Only used for HArrayGet and the UnsafeGetObject & |
| 645 | // UnsafeGetObjectVolatile intrinsics. |
| 646 | const Location index_; |
| 647 | |
| 648 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); |
| 649 | }; |
| 650 | |
| 651 | // Slow path generating a read barrier for a GC root. |
| 652 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { |
| 653 | public: |
| 654 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 655 | : SlowPathCode(instruction), out_(out), root_(root) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 656 | DCHECK(kEmitCompilerReadBarrier); |
| 657 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 658 | |
| 659 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 660 | LocationSummary* locations = instruction_->GetLocations(); |
| 661 | Register reg_out = out_.AsRegister<Register>(); |
| 662 | DCHECK(locations->CanCall()); |
| 663 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 664 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) |
| 665 | << "Unexpected instruction in read barrier for GC root slow path: " |
| 666 | << instruction_->DebugName(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 667 | |
| 668 | __ Bind(GetEntryLabel()); |
| 669 | SaveLiveRegisters(codegen, locations); |
| 670 | |
| 671 | InvokeRuntimeCallingConvention calling_convention; |
| 672 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 673 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); |
| 674 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pReadBarrierForRootSlow), |
| 675 | instruction_, |
| 676 | instruction_->GetDexPc(), |
| 677 | this); |
| 678 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); |
| 679 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); |
| 680 | |
| 681 | RestoreLiveRegisters(codegen, locations); |
| 682 | __ jmp(GetExitLabel()); |
| 683 | } |
| 684 | |
| 685 | const char* GetDescription() const OVERRIDE { return "ReadBarrierForRootSlowPathX86"; } |
| 686 | |
| 687 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 688 | const Location out_; |
| 689 | const Location root_; |
| 690 | |
| 691 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); |
| 692 | }; |
| 693 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 694 | #undef __ |
Chih-Hung Hsieh | fba3997 | 2016-05-11 11:26:48 -0700 | [diff] [blame] | 695 | // NOLINT on __ macro to suppress wrong warning/fix from clang-tidy. |
| 696 | #define __ down_cast<X86Assembler*>(GetAssembler())-> /* NOLINT */ |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 697 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 698 | inline Condition X86Condition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 699 | switch (cond) { |
| 700 | case kCondEQ: return kEqual; |
| 701 | case kCondNE: return kNotEqual; |
| 702 | case kCondLT: return kLess; |
| 703 | case kCondLE: return kLessEqual; |
| 704 | case kCondGT: return kGreater; |
| 705 | case kCondGE: return kGreaterEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 706 | case kCondB: return kBelow; |
| 707 | case kCondBE: return kBelowEqual; |
| 708 | case kCondA: return kAbove; |
| 709 | case kCondAE: return kAboveEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 710 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 711 | LOG(FATAL) << "Unreachable"; |
| 712 | UNREACHABLE(); |
| 713 | } |
| 714 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 715 | // Maps signed condition to unsigned condition and FP condition to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 716 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 717 | switch (cond) { |
| 718 | case kCondEQ: return kEqual; |
| 719 | case kCondNE: return kNotEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 720 | // Signed to unsigned, and FP to x86 name. |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 721 | case kCondLT: return kBelow; |
| 722 | case kCondLE: return kBelowEqual; |
| 723 | case kCondGT: return kAbove; |
| 724 | case kCondGE: return kAboveEqual; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 725 | // Unsigned remain unchanged. |
| 726 | case kCondB: return kBelow; |
| 727 | case kCondBE: return kBelowEqual; |
| 728 | case kCondA: return kAbove; |
| 729 | case kCondAE: return kAboveEqual; |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 730 | } |
| 731 | LOG(FATAL) << "Unreachable"; |
| 732 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 735 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 736 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 740 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 741 | } |
| 742 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 743 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 744 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 745 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 746 | } |
| 747 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 748 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 749 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 750 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 751 | } |
| 752 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 753 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 754 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 755 | return GetFloatingPointSpillSlotSize(); |
| 756 | } |
| 757 | |
| 758 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 759 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 760 | return GetFloatingPointSpillSlotSize(); |
| 761 | } |
| 762 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 763 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 764 | HInstruction* instruction, |
| 765 | uint32_t dex_pc, |
| 766 | SlowPathCode* slow_path) { |
| 767 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 768 | instruction, |
| 769 | dex_pc, |
| 770 | slow_path); |
| 771 | } |
| 772 | |
| 773 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 774 | HInstruction* instruction, |
| 775 | uint32_t dex_pc, |
| 776 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 777 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 778 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 779 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 780 | } |
| 781 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 782 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 783 | const X86InstructionSetFeatures& isa_features, |
| 784 | const CompilerOptions& compiler_options, |
| 785 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 786 | : CodeGenerator(graph, |
| 787 | kNumberOfCpuRegisters, |
| 788 | kNumberOfXmmRegisters, |
| 789 | kNumberOfRegisterPairs, |
| 790 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 791 | arraysize(kCoreCalleeSaves)) |
| 792 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 793 | 0, |
| 794 | compiler_options, |
| 795 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 796 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 797 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 798 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 799 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 800 | assembler_(graph->GetArena()), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 801 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 802 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 803 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 804 | pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 805 | simple_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 806 | string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 807 | constant_area_start_(-1), |
| 808 | fixups_to_jump_tables_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 809 | method_address_offset_(-1) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 810 | // Use a fake return address register to mimic Quick. |
| 811 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 812 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 813 | |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 814 | void CodeGeneratorX86::SetupBlockedRegisters() const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 815 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 816 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 817 | |
| 818 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 819 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 820 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 821 | UpdateBlockedPairRegisters(); |
| 822 | } |
| 823 | |
| 824 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 825 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 826 | X86ManagedRegister current = |
| 827 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 828 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 829 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 830 | blocked_register_pairs_[i] = true; |
| 831 | } |
| 832 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 833 | } |
| 834 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 835 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 836 | : InstructionCodeGenerator(graph, codegen), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 837 | assembler_(codegen->GetAssembler()), |
| 838 | codegen_(codegen) {} |
| 839 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 840 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 841 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 842 | } |
| 843 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 844 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 845 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 846 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 847 | bool skip_overflow_check = |
| 848 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 849 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 850 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 851 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 852 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 853 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 854 | } |
| 855 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 856 | if (HasEmptyFrame()) { |
| 857 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 858 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 859 | |
| 860 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 861 | Register reg = kCoreCalleeSaves[i]; |
| 862 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 863 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 864 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 865 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 869 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 870 | __ subl(ESP, Immediate(adjust)); |
| 871 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 872 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 876 | __ cfi().RememberState(); |
| 877 | if (!HasEmptyFrame()) { |
| 878 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 879 | __ addl(ESP, Immediate(adjust)); |
| 880 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 881 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 882 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 883 | Register reg = kCoreCalleeSaves[i]; |
| 884 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 885 | __ popl(reg); |
| 886 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 887 | __ cfi().Restore(DWARFReg(reg)); |
| 888 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 889 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 890 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 891 | __ ret(); |
| 892 | __ cfi().RestoreState(); |
| 893 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 896 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 897 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 898 | } |
| 899 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 900 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 901 | switch (type) { |
| 902 | case Primitive::kPrimBoolean: |
| 903 | case Primitive::kPrimByte: |
| 904 | case Primitive::kPrimChar: |
| 905 | case Primitive::kPrimShort: |
| 906 | case Primitive::kPrimInt: |
| 907 | case Primitive::kPrimNot: |
| 908 | return Location::RegisterLocation(EAX); |
| 909 | |
| 910 | case Primitive::kPrimLong: |
| 911 | return Location::RegisterPairLocation(EAX, EDX); |
| 912 | |
| 913 | case Primitive::kPrimVoid: |
| 914 | return Location::NoLocation(); |
| 915 | |
| 916 | case Primitive::kPrimDouble: |
| 917 | case Primitive::kPrimFloat: |
| 918 | return Location::FpuRegisterLocation(XMM0); |
| 919 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 920 | |
| 921 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 925 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 926 | } |
| 927 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 928 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 929 | switch (type) { |
| 930 | case Primitive::kPrimBoolean: |
| 931 | case Primitive::kPrimByte: |
| 932 | case Primitive::kPrimChar: |
| 933 | case Primitive::kPrimShort: |
| 934 | case Primitive::kPrimInt: |
| 935 | case Primitive::kPrimNot: { |
| 936 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 937 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 938 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 939 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 940 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 941 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 942 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 943 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 944 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 945 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 946 | uint32_t index = gp_index_; |
| 947 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 948 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 949 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 950 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 951 | calling_convention.GetRegisterPairAt(index)); |
| 952 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 953 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 954 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 959 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 960 | stack_index_++; |
| 961 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 962 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 963 | } else { |
| 964 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 969 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 970 | stack_index_ += 2; |
| 971 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 972 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 973 | } else { |
| 974 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 978 | case Primitive::kPrimVoid: |
| 979 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 980 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 981 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 982 | return Location::NoLocation(); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 983 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 984 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 985 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 986 | if (source.Equals(destination)) { |
| 987 | return; |
| 988 | } |
| 989 | if (destination.IsRegister()) { |
| 990 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 991 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 992 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 993 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 994 | } else { |
| 995 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 996 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 997 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 998 | } else if (destination.IsFpuRegister()) { |
| 999 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1000 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1001 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1002 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1003 | } else { |
| 1004 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1005 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1006 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1007 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1008 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1009 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1010 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1011 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1012 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1013 | } else if (source.IsConstant()) { |
| 1014 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1015 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1016 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1017 | } else { |
| 1018 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1019 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 1020 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 1026 | if (source.Equals(destination)) { |
| 1027 | return; |
| 1028 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1029 | if (destination.IsRegisterPair()) { |
| 1030 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1031 | EmitParallelMoves( |
| 1032 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 1033 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1034 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1035 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1036 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 1037 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1038 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1039 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 1040 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 1041 | __ psrlq(src_reg, Immediate(32)); |
| 1042 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1043 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1044 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1045 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1046 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 1047 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1048 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 1049 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1050 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1051 | if (source.IsFpuRegister()) { |
| 1052 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 1053 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1054 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1055 | } else if (source.IsRegisterPair()) { |
| 1056 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 1057 | // Create stack space for 2 elements. |
| 1058 | __ subl(ESP, Immediate(2 * elem_size)); |
| 1059 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 1060 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 1061 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 1062 | // And remove the temporary stack space we allocated. |
| 1063 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1064 | } else { |
| 1065 | LOG(FATAL) << "Unimplemented"; |
| 1066 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1067 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1068 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1069 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1070 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1071 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1072 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1073 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1074 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1075 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1076 | } else if (source.IsConstant()) { |
| 1077 | HConstant* constant = source.GetConstant(); |
| 1078 | int64_t value; |
| 1079 | if (constant->IsLongConstant()) { |
| 1080 | value = constant->AsLongConstant()->GetValue(); |
| 1081 | } else { |
| 1082 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1083 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1084 | } |
| 1085 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 1086 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1087 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1088 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1089 | EmitParallelMoves( |
| 1090 | Location::StackSlot(source.GetStackIndex()), |
| 1091 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1092 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1093 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1094 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 1095 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | } |
| 1099 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1100 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 1101 | DCHECK(location.IsRegister()); |
| 1102 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 1103 | } |
| 1104 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1105 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1106 | HParallelMove move(GetGraph()->GetArena()); |
| 1107 | if (dst_type == Primitive::kPrimLong && !src.IsConstant() && !src.IsFpuRegister()) { |
| 1108 | move.AddMove(src.ToLow(), dst.ToLow(), Primitive::kPrimInt, nullptr); |
| 1109 | move.AddMove(src.ToHigh(), dst.ToHigh(), Primitive::kPrimInt, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1110 | } else { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1111 | move.AddMove(src, dst, dst_type, nullptr); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1112 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1113 | GetMoveResolver()->EmitNativeCode(&move); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 1117 | if (location.IsRegister()) { |
| 1118 | locations->AddTemp(location); |
| 1119 | } else if (location.IsRegisterPair()) { |
| 1120 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 1121 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 1122 | } else { |
| 1123 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 1124 | } |
| 1125 | } |
| 1126 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1127 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1128 | DCHECK(!successor->IsExitBlock()); |
| 1129 | |
| 1130 | HBasicBlock* block = got->GetBlock(); |
| 1131 | HInstruction* previous = got->GetPrevious(); |
| 1132 | |
| 1133 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1134 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1135 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1136 | return; |
| 1137 | } |
| 1138 | |
| 1139 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1140 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1141 | } |
| 1142 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1143 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1147 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1148 | got->SetLocations(nullptr); |
| 1149 | } |
| 1150 | |
| 1151 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1152 | HandleGoto(got, got->GetSuccessor()); |
| 1153 | } |
| 1154 | |
| 1155 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1156 | try_boundary->SetLocations(nullptr); |
| 1157 | } |
| 1158 | |
| 1159 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1160 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1161 | if (!successor->IsExitBlock()) { |
| 1162 | HandleGoto(try_boundary, successor); |
| 1163 | } |
| 1164 | } |
| 1165 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1166 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1167 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1170 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1173 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1174 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1175 | LabelType* true_label, |
| 1176 | LabelType* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1177 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1178 | __ j(kUnordered, true_label); |
| 1179 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1180 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1181 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1182 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1185 | template<class LabelType> |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1186 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1187 | LabelType* true_label, |
| 1188 | LabelType* false_label) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1189 | LocationSummary* locations = cond->GetLocations(); |
| 1190 | Location left = locations->InAt(0); |
| 1191 | Location right = locations->InAt(1); |
| 1192 | IfCondition if_cond = cond->GetCondition(); |
| 1193 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1194 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1195 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1196 | IfCondition true_high_cond = if_cond; |
| 1197 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1198 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); // unsigned on lower part |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1199 | |
| 1200 | // Set the conditions for the test, remembering that == needs to be |
| 1201 | // decided using the low words. |
| 1202 | switch (if_cond) { |
| 1203 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1204 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1205 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1206 | break; |
| 1207 | case kCondLT: |
| 1208 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1209 | break; |
| 1210 | case kCondLE: |
| 1211 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1212 | break; |
| 1213 | case kCondGT: |
| 1214 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1215 | break; |
| 1216 | case kCondGE: |
| 1217 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1218 | break; |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1219 | case kCondB: |
| 1220 | false_high_cond = kCondA; |
| 1221 | break; |
| 1222 | case kCondBE: |
| 1223 | true_high_cond = kCondB; |
| 1224 | break; |
| 1225 | case kCondA: |
| 1226 | false_high_cond = kCondB; |
| 1227 | break; |
| 1228 | case kCondAE: |
| 1229 | true_high_cond = kCondA; |
| 1230 | break; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | if (right.IsConstant()) { |
| 1234 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1235 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1236 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1237 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1238 | codegen_->Compare32BitValue(left_high, val_high); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1239 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1240 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1241 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1242 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1243 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1244 | __ j(X86Condition(true_high_cond), true_label); |
| 1245 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1246 | } |
| 1247 | // Must be equal high, so compare the lows. |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1248 | codegen_->Compare32BitValue(left_low, val_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1249 | } else if (right.IsRegisterPair()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1250 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1251 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1252 | |
| 1253 | __ cmpl(left_high, right_high); |
| 1254 | if (if_cond == kCondNE) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1255 | __ j(X86Condition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1256 | } else if (if_cond == kCondEQ) { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1257 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1258 | } else { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1259 | __ j(X86Condition(true_high_cond), true_label); |
| 1260 | __ j(X86Condition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1261 | } |
| 1262 | // Must be equal high, so compare the lows. |
| 1263 | __ cmpl(left_low, right_low); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1264 | } else { |
| 1265 | DCHECK(right.IsDoubleStackSlot()); |
| 1266 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
| 1267 | if (if_cond == kCondNE) { |
| 1268 | __ j(X86Condition(true_high_cond), true_label); |
| 1269 | } else if (if_cond == kCondEQ) { |
| 1270 | __ j(X86Condition(false_high_cond), false_label); |
| 1271 | } else { |
| 1272 | __ j(X86Condition(true_high_cond), true_label); |
| 1273 | __ j(X86Condition(false_high_cond), false_label); |
| 1274 | } |
| 1275 | // Must be equal high, so compare the lows. |
| 1276 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1277 | } |
| 1278 | // The last comparison might be unsigned. |
| 1279 | __ j(final_condition, true_label); |
| 1280 | } |
| 1281 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1282 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, |
| 1283 | Location rhs, |
| 1284 | HInstruction* insn, |
| 1285 | bool is_double) { |
| 1286 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); |
| 1287 | if (is_double) { |
| 1288 | if (rhs.IsFpuRegister()) { |
| 1289 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1290 | } else if (const_area != nullptr) { |
| 1291 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1292 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), |
| 1293 | codegen_->LiteralDoubleAddress( |
| 1294 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 1295 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1296 | } else { |
| 1297 | DCHECK(rhs.IsDoubleStackSlot()); |
| 1298 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1299 | } |
| 1300 | } else { |
| 1301 | if (rhs.IsFpuRegister()) { |
| 1302 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1303 | } else if (const_area != nullptr) { |
| 1304 | DCHECK(const_area->IsEmittedAtUseSite()); |
| 1305 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), |
| 1306 | codegen_->LiteralFloatAddress( |
| 1307 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 1308 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 1309 | } else { |
| 1310 | DCHECK(rhs.IsStackSlot()); |
| 1311 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); |
| 1312 | } |
| 1313 | } |
| 1314 | } |
| 1315 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1316 | template<class LabelType> |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1317 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1318 | LabelType* true_target_in, |
| 1319 | LabelType* false_target_in) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1320 | // Generated branching requires both targets to be explicit. If either of the |
| 1321 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1322 | LabelType fallthrough_target; |
| 1323 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; |
| 1324 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1325 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1326 | LocationSummary* locations = condition->GetLocations(); |
| 1327 | Location left = locations->InAt(0); |
| 1328 | Location right = locations->InAt(1); |
| 1329 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1330 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1331 | switch (type) { |
| 1332 | case Primitive::kPrimLong: |
| 1333 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1334 | break; |
| 1335 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1336 | GenerateFPCompare(left, right, condition, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1337 | GenerateFPJumps(condition, true_target, false_target); |
| 1338 | break; |
| 1339 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1340 | GenerateFPCompare(left, right, condition, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1341 | GenerateFPJumps(condition, true_target, false_target); |
| 1342 | break; |
| 1343 | default: |
| 1344 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1345 | } |
| 1346 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1347 | if (false_target != &fallthrough_target) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1348 | __ jmp(false_target); |
| 1349 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1350 | |
| 1351 | if (fallthrough_target.IsLinked()) { |
| 1352 | __ Bind(&fallthrough_target); |
| 1353 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1354 | } |
| 1355 | |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1356 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { |
| 1357 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS |
| 1358 | // are set only strictly before `branch`. We can't use the eflags on long/FP |
| 1359 | // conditions if they are materialized due to the complex branching. |
| 1360 | return cond->IsCondition() && |
| 1361 | cond->GetNext() == branch && |
| 1362 | cond->InputAt(0)->GetType() != Primitive::kPrimLong && |
| 1363 | !Primitive::IsFloatingPointType(cond->InputAt(0)->GetType()); |
| 1364 | } |
| 1365 | |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1366 | template<class LabelType> |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1367 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1368 | size_t condition_input_index, |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1369 | LabelType* true_target, |
| 1370 | LabelType* false_target) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1371 | HInstruction* cond = instruction->InputAt(condition_input_index); |
| 1372 | |
| 1373 | if (true_target == nullptr && false_target == nullptr) { |
| 1374 | // Nothing to do. The code always falls through. |
| 1375 | return; |
| 1376 | } else if (cond->IsIntConstant()) { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1377 | // Constant condition, statically compared against "true" (integer value 1). |
| 1378 | if (cond->AsIntConstant()->IsTrue()) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1379 | if (true_target != nullptr) { |
| 1380 | __ jmp(true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1381 | } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1382 | } else { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1383 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1384 | if (false_target != nullptr) { |
| 1385 | __ jmp(false_target); |
| 1386 | } |
| 1387 | } |
| 1388 | return; |
| 1389 | } |
| 1390 | |
| 1391 | // The following code generates these patterns: |
| 1392 | // (1) true_target == nullptr && false_target != nullptr |
| 1393 | // - opposite condition true => branch to false_target |
| 1394 | // (2) true_target != nullptr && false_target == nullptr |
| 1395 | // - condition true => branch to true_target |
| 1396 | // (3) true_target != nullptr && false_target != nullptr |
| 1397 | // - condition true => branch to true_target |
| 1398 | // - branch to false_target |
| 1399 | if (IsBooleanValueOrMaterializedCondition(cond)) { |
| 1400 | if (AreEflagsSetFrom(cond, instruction)) { |
| 1401 | if (true_target == nullptr) { |
| 1402 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); |
| 1403 | } else { |
| 1404 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); |
| 1405 | } |
| 1406 | } else { |
| 1407 | // Materialized condition, compare against 0. |
| 1408 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); |
| 1409 | if (lhs.IsRegister()) { |
| 1410 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1411 | } else { |
| 1412 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1413 | } |
| 1414 | if (true_target == nullptr) { |
| 1415 | __ j(kEqual, false_target); |
| 1416 | } else { |
| 1417 | __ j(kNotEqual, true_target); |
| 1418 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1419 | } |
| 1420 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1421 | // Condition has not been materialized, use its inputs as the comparison and |
| 1422 | // its condition as the branch condition. |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1423 | HCondition* condition = cond->AsCondition(); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1424 | |
| 1425 | // If this is a long or FP comparison that has been folded into |
| 1426 | // the HCondition, generate the comparison directly. |
| 1427 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1428 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1429 | GenerateCompareTestAndBranch(condition, true_target, false_target); |
| 1430 | return; |
| 1431 | } |
| 1432 | |
| 1433 | Location lhs = condition->GetLocations()->InAt(0); |
| 1434 | Location rhs = condition->GetLocations()->InAt(1); |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1435 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1436 | if (rhs.IsRegister()) { |
| 1437 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1438 | } else if (rhs.IsConstant()) { |
| 1439 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1440 | codegen_->Compare32BitValue(lhs.AsRegister<Register>(), constant); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1441 | } else { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1442 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1443 | } |
| 1444 | if (true_target == nullptr) { |
| 1445 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); |
| 1446 | } else { |
Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1447 | __ j(X86Condition(condition->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1448 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1449 | } |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1450 | |
| 1451 | // If neither branch falls through (case 3), the conditional branch to `true_target` |
| 1452 | // was already emitted (case 2) and we need to emit a jump to `false_target`. |
| 1453 | if (true_target != nullptr && false_target != nullptr) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1454 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1458 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1459 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr); |
| 1460 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1461 | locations->SetInAt(0, Location::Any()); |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1466 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); |
| 1467 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); |
| 1468 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? |
| 1469 | nullptr : codegen_->GetLabelOf(true_successor); |
| 1470 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? |
| 1471 | nullptr : codegen_->GetLabelOf(false_successor); |
| 1472 | GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
| 1475 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1476 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1477 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1478 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1479 | locations->SetInAt(0, Location::Any()); |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1484 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1485 | GenerateTestAndBranch<Label>(deoptimize, |
| 1486 | /* condition_input_index */ 0, |
| 1487 | slow_path->GetEntryLabel(), |
| 1488 | /* false_target */ nullptr); |
| 1489 | } |
| 1490 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1491 | static bool SelectCanUseCMOV(HSelect* select) { |
| 1492 | // There are no conditional move instructions for XMMs. |
| 1493 | if (Primitive::IsFloatingPointType(select->GetType())) { |
| 1494 | return false; |
| 1495 | } |
| 1496 | |
| 1497 | // A FP condition doesn't generate the single CC that we need. |
| 1498 | // In 32 bit mode, a long condition doesn't generate a single CC either. |
| 1499 | HInstruction* condition = select->GetCondition(); |
| 1500 | if (condition->IsCondition()) { |
| 1501 | Primitive::Type compare_type = condition->InputAt(0)->GetType(); |
| 1502 | if (compare_type == Primitive::kPrimLong || |
| 1503 | Primitive::IsFloatingPointType(compare_type)) { |
| 1504 | return false; |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | // We can generate a CMOV for this Select. |
| 1509 | return true; |
| 1510 | } |
| 1511 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1512 | void LocationsBuilderX86::VisitSelect(HSelect* select) { |
| 1513 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1514 | if (Primitive::IsFloatingPointType(select->GetType())) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1515 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1516 | locations->SetInAt(1, Location::Any()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1517 | } else { |
| 1518 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1519 | if (SelectCanUseCMOV(select)) { |
| 1520 | if (select->InputAt(1)->IsConstant()) { |
| 1521 | // Cmov can't handle a constant value. |
| 1522 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1523 | } else { |
| 1524 | locations->SetInAt(1, Location::Any()); |
| 1525 | } |
| 1526 | } else { |
| 1527 | locations->SetInAt(1, Location::Any()); |
| 1528 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1529 | } |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1530 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { |
| 1531 | locations->SetInAt(2, Location::RequiresRegister()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1532 | } |
| 1533 | locations->SetOut(Location::SameAsFirstInput()); |
| 1534 | } |
| 1535 | |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1536 | void InstructionCodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { |
| 1537 | Register lhs_reg = lhs.AsRegister<Register>(); |
| 1538 | if (rhs.IsConstant()) { |
| 1539 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1540 | codegen_->Compare32BitValue(lhs_reg, value); |
| 1541 | } else if (rhs.IsStackSlot()) { |
| 1542 | __ cmpl(lhs_reg, Address(ESP, rhs.GetStackIndex())); |
| 1543 | } else { |
| 1544 | __ cmpl(lhs_reg, rhs.AsRegister<Register>()); |
| 1545 | } |
| 1546 | } |
| 1547 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1548 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { |
| 1549 | LocationSummary* locations = select->GetLocations(); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1550 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1551 | if (SelectCanUseCMOV(select)) { |
| 1552 | // If both the condition and the source types are integer, we can generate |
| 1553 | // a CMOV to implement Select. |
| 1554 | |
| 1555 | HInstruction* select_condition = select->GetCondition(); |
| 1556 | Condition cond = kNotEqual; |
| 1557 | |
| 1558 | // Figure out how to test the 'condition'. |
| 1559 | if (select_condition->IsCondition()) { |
| 1560 | HCondition* condition = select_condition->AsCondition(); |
| 1561 | if (!condition->IsEmittedAtUseSite()) { |
| 1562 | // This was a previously materialized condition. |
| 1563 | // Can we use the existing condition code? |
| 1564 | if (AreEflagsSetFrom(condition, select)) { |
| 1565 | // Materialization was the previous instruction. Condition codes are right. |
| 1566 | cond = X86Condition(condition->GetCondition()); |
| 1567 | } else { |
| 1568 | // No, we have to recreate the condition code. |
| 1569 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1570 | __ testl(cond_reg, cond_reg); |
| 1571 | } |
| 1572 | } else { |
| 1573 | // We can't handle FP or long here. |
| 1574 | DCHECK_NE(condition->InputAt(0)->GetType(), Primitive::kPrimLong); |
| 1575 | DCHECK(!Primitive::IsFloatingPointType(condition->InputAt(0)->GetType())); |
| 1576 | LocationSummary* cond_locations = condition->GetLocations(); |
| 1577 | GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); |
| 1578 | cond = X86Condition(condition->GetCondition()); |
| 1579 | } |
| 1580 | } else { |
| 1581 | // Must be a boolean condition, which needs to be compared to 0. |
| 1582 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); |
| 1583 | __ testl(cond_reg, cond_reg); |
| 1584 | } |
| 1585 | |
| 1586 | // If the condition is true, overwrite the output, which already contains false. |
| 1587 | Location false_loc = locations->InAt(0); |
| 1588 | Location true_loc = locations->InAt(1); |
| 1589 | if (select->GetType() == Primitive::kPrimLong) { |
| 1590 | // 64 bit conditional move. |
| 1591 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); |
| 1592 | Register false_low = false_loc.AsRegisterPairLow<Register>(); |
| 1593 | if (true_loc.IsRegisterPair()) { |
| 1594 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); |
| 1595 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); |
| 1596 | } else { |
| 1597 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); |
| 1598 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); |
| 1599 | } |
| 1600 | } else { |
| 1601 | // 32 bit conditional move. |
| 1602 | Register false_reg = false_loc.AsRegister<Register>(); |
| 1603 | if (true_loc.IsRegister()) { |
| 1604 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); |
| 1605 | } else { |
| 1606 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); |
| 1607 | } |
| 1608 | } |
| 1609 | } else { |
| 1610 | NearLabel false_target; |
| 1611 | GenerateTestAndBranch<NearLabel>( |
| 1612 | select, /* condition_input_index */ 2, /* true_target */ nullptr, &false_target); |
| 1613 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); |
| 1614 | __ Bind(&false_target); |
| 1615 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1618 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { |
| 1619 | new (GetGraph()->GetArena()) LocationSummary(info); |
| 1620 | } |
| 1621 | |
David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1622 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { |
| 1623 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. |
David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | void CodeGeneratorX86::GenerateNop() { |
| 1627 | __ nop(); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1630 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1631 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1632 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1633 | // Handle the long/FP comparisons made in instruction simplification. |
| 1634 | switch (cond->InputAt(0)->GetType()) { |
| 1635 | case Primitive::kPrimLong: { |
| 1636 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1637 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1638 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1639 | locations->SetOut(Location::RequiresRegister()); |
| 1640 | } |
| 1641 | break; |
| 1642 | } |
| 1643 | case Primitive::kPrimFloat: |
| 1644 | case Primitive::kPrimDouble: { |
| 1645 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1646 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 1647 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); |
| 1648 | } else if (cond->InputAt(1)->IsConstant()) { |
| 1649 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1650 | } else { |
| 1651 | locations->SetInAt(1, Location::Any()); |
| 1652 | } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1653 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1654 | locations->SetOut(Location::RequiresRegister()); |
| 1655 | } |
| 1656 | break; |
| 1657 | } |
| 1658 | default: |
| 1659 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1660 | locations->SetInAt(1, Location::Any()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1661 | if (!cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1662 | // We need a byte register. |
| 1663 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1664 | } |
| 1665 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1666 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1669 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1670 | if (cond->IsEmittedAtUseSite()) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1671 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1672 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1673 | |
| 1674 | LocationSummary* locations = cond->GetLocations(); |
| 1675 | Location lhs = locations->InAt(0); |
| 1676 | Location rhs = locations->InAt(1); |
| 1677 | Register reg = locations->Out().AsRegister<Register>(); |
Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1678 | NearLabel true_label, false_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1679 | |
| 1680 | switch (cond->InputAt(0)->GetType()) { |
| 1681 | default: { |
| 1682 | // Integer case. |
| 1683 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1684 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1685 | __ xorl(reg, reg); |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1686 | GenerateIntCompare(lhs, rhs); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1687 | __ setb(X86Condition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1688 | return; |
| 1689 | } |
| 1690 | case Primitive::kPrimLong: |
| 1691 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1692 | break; |
| 1693 | case Primitive::kPrimFloat: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1694 | GenerateFPCompare(lhs, rhs, cond, false); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1695 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1696 | break; |
| 1697 | case Primitive::kPrimDouble: |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1698 | GenerateFPCompare(lhs, rhs, cond, true); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1699 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1700 | break; |
| 1701 | } |
| 1702 | |
| 1703 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1704 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1705 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1706 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1707 | __ Bind(&false_label); |
| 1708 | __ xorl(reg, reg); |
| 1709 | __ jmp(&done_label); |
| 1710 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1711 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1712 | __ Bind(&true_label); |
| 1713 | __ movl(reg, Immediate(1)); |
| 1714 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1718 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1722 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1726 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1730 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1734 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1738 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1742 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1746 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1750 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1754 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1758 | HandleCondition(comp); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1762 | HandleCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1765 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1766 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1770 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1774 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1778 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1782 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1786 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1790 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1794 | HandleCondition(comp); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1797 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1798 | LocationSummary* locations = |
| 1799 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1800 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1803 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1804 | // Will be generated at use site. |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1805 | } |
| 1806 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1807 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1808 | LocationSummary* locations = |
| 1809 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1810 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1811 | } |
| 1812 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1813 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1814 | // Will be generated at use site. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1817 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1818 | LocationSummary* locations = |
| 1819 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1820 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1821 | } |
| 1822 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1823 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1824 | // Will be generated at use site. |
| 1825 | } |
| 1826 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1827 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1828 | LocationSummary* locations = |
| 1829 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1830 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1831 | } |
| 1832 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1833 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1834 | // Will be generated at use site. |
| 1835 | } |
| 1836 | |
| 1837 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1838 | LocationSummary* locations = |
| 1839 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1840 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1841 | } |
| 1842 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1843 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1844 | // Will be generated at use site. |
| 1845 | } |
| 1846 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1847 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1848 | memory_barrier->SetLocations(nullptr); |
| 1849 | } |
| 1850 | |
| 1851 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1852 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1855 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1856 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1859 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1860 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1863 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1864 | LocationSummary* locations = |
| 1865 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1866 | switch (ret->InputAt(0)->GetType()) { |
| 1867 | case Primitive::kPrimBoolean: |
| 1868 | case Primitive::kPrimByte: |
| 1869 | case Primitive::kPrimChar: |
| 1870 | case Primitive::kPrimShort: |
| 1871 | case Primitive::kPrimInt: |
| 1872 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1873 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1874 | break; |
| 1875 | |
| 1876 | case Primitive::kPrimLong: |
| 1877 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1878 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1879 | break; |
| 1880 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1881 | case Primitive::kPrimFloat: |
| 1882 | case Primitive::kPrimDouble: |
| 1883 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1884 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1885 | break; |
| 1886 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1887 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1888 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1889 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1890 | } |
| 1891 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1892 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1893 | if (kIsDebugBuild) { |
| 1894 | switch (ret->InputAt(0)->GetType()) { |
| 1895 | case Primitive::kPrimBoolean: |
| 1896 | case Primitive::kPrimByte: |
| 1897 | case Primitive::kPrimChar: |
| 1898 | case Primitive::kPrimShort: |
| 1899 | case Primitive::kPrimInt: |
| 1900 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1901 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1902 | break; |
| 1903 | |
| 1904 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1905 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1906 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1907 | break; |
| 1908 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1909 | case Primitive::kPrimFloat: |
| 1910 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1911 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1912 | break; |
| 1913 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1914 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1915 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1916 | } |
| 1917 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1918 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1921 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1922 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1923 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1924 | // the method_idx. |
| 1925 | HandleInvoke(invoke); |
| 1926 | } |
| 1927 | |
| 1928 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1929 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1930 | } |
| 1931 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1932 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1933 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1934 | // art::PrepareForRegisterAllocation. |
| 1935 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1936 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1937 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1938 | if (intrinsic.TryDispatch(invoke)) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1939 | if (invoke->GetLocations()->CanCall() && invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 1940 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1941 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1942 | return; |
| 1943 | } |
| 1944 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1945 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1946 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1947 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. |
| 1948 | if (invoke->HasPcRelativeDexCache()) { |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1949 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 1950 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1951 | } |
| 1952 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1953 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1954 | if (invoke->GetLocations()->Intrinsified()) { |
| 1955 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1956 | intrinsic.Dispatch(invoke); |
| 1957 | return true; |
| 1958 | } |
| 1959 | return false; |
| 1960 | } |
| 1961 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1962 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1963 | // Explicit clinit checks triggered by static invokes must have been pruned by |
| 1964 | // art::PrepareForRegisterAllocation. |
| 1965 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1966 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1967 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1968 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1969 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1970 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1971 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1972 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1973 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1974 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1978 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
| 1979 | if (intrinsic.TryDispatch(invoke)) { |
| 1980 | return; |
| 1981 | } |
| 1982 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1983 | HandleInvoke(invoke); |
| 1984 | } |
| 1985 | |
| 1986 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1987 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1988 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1991 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1992 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1993 | return; |
| 1994 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1995 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1996 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1997 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1998 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2001 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2002 | // This call to HandleInvoke allocates a temporary (core) register |
| 2003 | // which is also used to transfer the hidden argument from FP to |
| 2004 | // core register. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2005 | HandleInvoke(invoke); |
| 2006 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2007 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 2011 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2012 | LocationSummary* locations = invoke->GetLocations(); |
| 2013 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2014 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2015 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 2016 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2017 | Location receiver = locations->InAt(0); |
| 2018 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2019 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2020 | // Set the hidden argument. This is safe to do this here, as XMM7 |
| 2021 | // won't be modified thereafter, before the `call` instruction. |
| 2022 | DCHECK_EQ(XMM7, hidden_reg); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2023 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2024 | __ movd(hidden_reg, temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2025 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2026 | if (receiver.IsStackSlot()) { |
| 2027 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2028 | // /* HeapReference<Class> */ temp = temp->klass_ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2029 | __ movl(temp, Address(temp, class_offset)); |
| 2030 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2031 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2032 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2033 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2034 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2035 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 2036 | // emit a read barrier for the previous class reference load. |
| 2037 | // However this is not required in practice, as this is an |
| 2038 | // intermediate/temporary reference and because the current |
| 2039 | // concurrent copying collector keeps the from-space memory |
| 2040 | // intact/accessible until the end of the marking phase (the |
| 2041 | // concurrent copying collector may not in the future). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2042 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2043 | // temp = temp->GetImtEntryAt(method_offset); |
| 2044 | __ movl(temp, Address(temp, method_offset)); |
| 2045 | // call temp->GetEntryPoint(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2046 | __ call(Address(temp, |
| 2047 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2048 | |
| 2049 | DCHECK(!codegen_->IsLeafMethod()); |
| 2050 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 2051 | } |
| 2052 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2053 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 2054 | LocationSummary* locations = |
| 2055 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2056 | switch (neg->GetResultType()) { |
| 2057 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2058 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2059 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2060 | locations->SetOut(Location::SameAsFirstInput()); |
| 2061 | break; |
| 2062 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2063 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2064 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2065 | locations->SetOut(Location::SameAsFirstInput()); |
| 2066 | locations->AddTemp(Location::RequiresRegister()); |
| 2067 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2068 | break; |
| 2069 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2070 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2071 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2072 | locations->SetOut(Location::SameAsFirstInput()); |
| 2073 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2074 | break; |
| 2075 | |
| 2076 | default: |
| 2077 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 2082 | LocationSummary* locations = neg->GetLocations(); |
| 2083 | Location out = locations->Out(); |
| 2084 | Location in = locations->InAt(0); |
| 2085 | switch (neg->GetResultType()) { |
| 2086 | case Primitive::kPrimInt: |
| 2087 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2088 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2089 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2090 | break; |
| 2091 | |
| 2092 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2093 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2094 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2095 | __ negl(out.AsRegisterPairLow<Register>()); |
| 2096 | // Negation is similar to subtraction from zero. The least |
| 2097 | // significant byte triggers a borrow when it is different from |
| 2098 | // zero; to take it into account, add 1 to the most significant |
| 2099 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 2100 | // operation. |
| 2101 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 2102 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 2103 | break; |
| 2104 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2105 | case Primitive::kPrimFloat: { |
| 2106 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2107 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 2108 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2109 | // Implement float negation with an exclusive or with value |
| 2110 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 2111 | // single-precision floating-point number). |
| 2112 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 2113 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2114 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2115 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2116 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2117 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2118 | case Primitive::kPrimDouble: { |
| 2119 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2120 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2121 | // Implement double negation with an exclusive or with value |
| 2122 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 2123 | // a double-precision floating-point number). |
| 2124 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2125 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2126 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2127 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2128 | |
| 2129 | default: |
| 2130 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 2131 | } |
| 2132 | } |
| 2133 | |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2134 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2135 | LocationSummary* locations = |
| 2136 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 2137 | DCHECK(Primitive::IsFloatingPointType(neg->GetType())); |
| 2138 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2139 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2140 | locations->SetOut(Location::SameAsFirstInput()); |
| 2141 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2142 | } |
| 2143 | |
| 2144 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { |
| 2145 | LocationSummary* locations = neg->GetLocations(); |
| 2146 | Location out = locations->Out(); |
| 2147 | DCHECK(locations->InAt(0).Equals(out)); |
| 2148 | |
| 2149 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 2150 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 2151 | if (neg->GetType() == Primitive::kPrimFloat) { |
| 2152 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), constant_area)); |
| 2153 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
| 2154 | } else { |
| 2155 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), constant_area)); |
| 2156 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
| 2157 | } |
| 2158 | } |
| 2159 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2160 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2161 | Primitive::Type result_type = conversion->GetResultType(); |
| 2162 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2163 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2164 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2165 | // The float-to-long and double-to-long type conversions rely on a |
| 2166 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2167 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2168 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 2169 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2170 | ? LocationSummary::kCall |
| 2171 | : LocationSummary::kNoCall; |
| 2172 | LocationSummary* locations = |
| 2173 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 2174 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 2175 | // The Java language does not allow treating boolean as an integral type but |
| 2176 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2177 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2178 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2179 | case Primitive::kPrimByte: |
| 2180 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2181 | case Primitive::kPrimLong: { |
| 2182 | // Type conversion from long to byte is a result of code transformations. |
| 2183 | HInstruction* input = conversion->InputAt(0); |
| 2184 | Location input_location = input->IsConstant() |
| 2185 | ? Location::ConstantLocation(input->AsConstant()) |
| 2186 | : Location::RegisterPairLocation(EAX, EDX); |
| 2187 | locations->SetInAt(0, input_location); |
| 2188 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2189 | // the validation of the linear scan implementation |
| 2190 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2191 | break; |
| 2192 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2193 | case Primitive::kPrimBoolean: |
| 2194 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2195 | case Primitive::kPrimShort: |
| 2196 | case Primitive::kPrimInt: |
| 2197 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2198 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 2199 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 2200 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 2201 | // the validation of the linear scan implementation |
| 2202 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2203 | break; |
| 2204 | |
| 2205 | default: |
| 2206 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2207 | << " to " << result_type; |
| 2208 | } |
| 2209 | break; |
| 2210 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2211 | case Primitive::kPrimShort: |
| 2212 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2213 | case Primitive::kPrimLong: |
| 2214 | // Type conversion from long to short is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2215 | case Primitive::kPrimBoolean: |
| 2216 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2217 | case Primitive::kPrimByte: |
| 2218 | case Primitive::kPrimInt: |
| 2219 | case Primitive::kPrimChar: |
| 2220 | // Processing a Dex `int-to-short' instruction. |
| 2221 | locations->SetInAt(0, Location::Any()); |
| 2222 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2223 | break; |
| 2224 | |
| 2225 | default: |
| 2226 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2227 | << " to " << result_type; |
| 2228 | } |
| 2229 | break; |
| 2230 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2231 | case Primitive::kPrimInt: |
| 2232 | switch (input_type) { |
| 2233 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2234 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2235 | locations->SetInAt(0, Location::Any()); |
| 2236 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2237 | break; |
| 2238 | |
| 2239 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2240 | // Processing a Dex `float-to-int' instruction. |
| 2241 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2242 | locations->SetOut(Location::RequiresRegister()); |
| 2243 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 2244 | break; |
| 2245 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2246 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2247 | // Processing a Dex `double-to-int' instruction. |
| 2248 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2249 | locations->SetOut(Location::RequiresRegister()); |
| 2250 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2251 | break; |
| 2252 | |
| 2253 | default: |
| 2254 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2255 | << " to " << result_type; |
| 2256 | } |
| 2257 | break; |
| 2258 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2259 | case Primitive::kPrimLong: |
| 2260 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2261 | case Primitive::kPrimBoolean: |
| 2262 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2263 | case Primitive::kPrimByte: |
| 2264 | case Primitive::kPrimShort: |
| 2265 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2266 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2267 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2268 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 2269 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 2270 | break; |
| 2271 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2272 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2273 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2274 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2275 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2276 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 2277 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 2278 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2279 | // The runtime helper puts the result in EAX, EDX. |
| 2280 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2281 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2282 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2283 | |
| 2284 | default: |
| 2285 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2286 | << " to " << result_type; |
| 2287 | } |
| 2288 | break; |
| 2289 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2290 | case Primitive::kPrimChar: |
| 2291 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2292 | case Primitive::kPrimLong: |
| 2293 | // Type conversion from long to char is a result of code transformations. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2294 | case Primitive::kPrimBoolean: |
| 2295 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2296 | case Primitive::kPrimByte: |
| 2297 | case Primitive::kPrimShort: |
| 2298 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2299 | // Processing a Dex `int-to-char' instruction. |
| 2300 | locations->SetInAt(0, Location::Any()); |
| 2301 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2302 | break; |
| 2303 | |
| 2304 | default: |
| 2305 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2306 | << " to " << result_type; |
| 2307 | } |
| 2308 | break; |
| 2309 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2310 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2311 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2312 | case Primitive::kPrimBoolean: |
| 2313 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2314 | case Primitive::kPrimByte: |
| 2315 | case Primitive::kPrimShort: |
| 2316 | case Primitive::kPrimInt: |
| 2317 | case Primitive::kPrimChar: |
| 2318 | // Processing a Dex `int-to-float' instruction. |
| 2319 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2320 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2321 | break; |
| 2322 | |
| 2323 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2324 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2325 | locations->SetInAt(0, Location::Any()); |
| 2326 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2327 | break; |
| 2328 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2329 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2330 | // Processing a Dex `double-to-float' instruction. |
| 2331 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2332 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2333 | break; |
| 2334 | |
| 2335 | default: |
| 2336 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2337 | << " to " << result_type; |
| 2338 | }; |
| 2339 | break; |
| 2340 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2341 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2342 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2343 | case Primitive::kPrimBoolean: |
| 2344 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2345 | case Primitive::kPrimByte: |
| 2346 | case Primitive::kPrimShort: |
| 2347 | case Primitive::kPrimInt: |
| 2348 | case Primitive::kPrimChar: |
| 2349 | // Processing a Dex `int-to-double' instruction. |
| 2350 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2351 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2352 | break; |
| 2353 | |
| 2354 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2355 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2356 | locations->SetInAt(0, Location::Any()); |
| 2357 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2358 | break; |
| 2359 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2360 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2361 | // Processing a Dex `float-to-double' instruction. |
| 2362 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2363 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2364 | break; |
| 2365 | |
| 2366 | default: |
| 2367 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2368 | << " to " << result_type; |
| 2369 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2370 | break; |
| 2371 | |
| 2372 | default: |
| 2373 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2374 | << " to " << result_type; |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2379 | LocationSummary* locations = conversion->GetLocations(); |
| 2380 | Location out = locations->Out(); |
| 2381 | Location in = locations->InAt(0); |
| 2382 | Primitive::Type result_type = conversion->GetResultType(); |
| 2383 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2384 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2385 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2386 | case Primitive::kPrimByte: |
| 2387 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2388 | case Primitive::kPrimLong: |
| 2389 | // Type conversion from long to byte is a result of code transformations. |
| 2390 | if (in.IsRegisterPair()) { |
| 2391 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); |
| 2392 | } else { |
| 2393 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2394 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2395 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2396 | } |
| 2397 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2398 | case Primitive::kPrimBoolean: |
| 2399 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2400 | case Primitive::kPrimShort: |
| 2401 | case Primitive::kPrimInt: |
| 2402 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2403 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2404 | if (in.IsRegister()) { |
| 2405 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2406 | } else { |
| 2407 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2408 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2409 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2410 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2411 | break; |
| 2412 | |
| 2413 | default: |
| 2414 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2415 | << " to " << result_type; |
| 2416 | } |
| 2417 | break; |
| 2418 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2419 | case Primitive::kPrimShort: |
| 2420 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2421 | case Primitive::kPrimLong: |
| 2422 | // Type conversion from long to short is a result of code transformations. |
| 2423 | if (in.IsRegisterPair()) { |
| 2424 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2425 | } else if (in.IsDoubleStackSlot()) { |
| 2426 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2427 | } else { |
| 2428 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2429 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2430 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
| 2431 | } |
| 2432 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2433 | case Primitive::kPrimBoolean: |
| 2434 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2435 | case Primitive::kPrimByte: |
| 2436 | case Primitive::kPrimInt: |
| 2437 | case Primitive::kPrimChar: |
| 2438 | // Processing a Dex `int-to-short' instruction. |
| 2439 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2440 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2441 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2442 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2443 | } else { |
| 2444 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2445 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2446 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2447 | } |
| 2448 | break; |
| 2449 | |
| 2450 | default: |
| 2451 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2452 | << " to " << result_type; |
| 2453 | } |
| 2454 | break; |
| 2455 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2456 | case Primitive::kPrimInt: |
| 2457 | switch (input_type) { |
| 2458 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2459 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2460 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2461 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2462 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2463 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2464 | } else { |
| 2465 | DCHECK(in.IsConstant()); |
| 2466 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2467 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2468 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2469 | } |
| 2470 | break; |
| 2471 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2472 | case Primitive::kPrimFloat: { |
| 2473 | // Processing a Dex `float-to-int' instruction. |
| 2474 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2475 | Register output = out.AsRegister<Register>(); |
| 2476 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2477 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2478 | |
| 2479 | __ movl(output, Immediate(kPrimIntMax)); |
| 2480 | // temp = int-to-float(output) |
| 2481 | __ cvtsi2ss(temp, output); |
| 2482 | // if input >= temp goto done |
| 2483 | __ comiss(input, temp); |
| 2484 | __ j(kAboveEqual, &done); |
| 2485 | // if input == NaN goto nan |
| 2486 | __ j(kUnordered, &nan); |
| 2487 | // output = float-to-int-truncate(input) |
| 2488 | __ cvttss2si(output, input); |
| 2489 | __ jmp(&done); |
| 2490 | __ Bind(&nan); |
| 2491 | // output = 0 |
| 2492 | __ xorl(output, output); |
| 2493 | __ Bind(&done); |
| 2494 | break; |
| 2495 | } |
| 2496 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2497 | case Primitive::kPrimDouble: { |
| 2498 | // Processing a Dex `double-to-int' instruction. |
| 2499 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2500 | Register output = out.AsRegister<Register>(); |
| 2501 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2502 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2503 | |
| 2504 | __ movl(output, Immediate(kPrimIntMax)); |
| 2505 | // temp = int-to-double(output) |
| 2506 | __ cvtsi2sd(temp, output); |
| 2507 | // if input >= temp goto done |
| 2508 | __ comisd(input, temp); |
| 2509 | __ j(kAboveEqual, &done); |
| 2510 | // if input == NaN goto nan |
| 2511 | __ j(kUnordered, &nan); |
| 2512 | // output = double-to-int-truncate(input) |
| 2513 | __ cvttsd2si(output, input); |
| 2514 | __ jmp(&done); |
| 2515 | __ Bind(&nan); |
| 2516 | // output = 0 |
| 2517 | __ xorl(output, output); |
| 2518 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2519 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2520 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2521 | |
| 2522 | default: |
| 2523 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2524 | << " to " << result_type; |
| 2525 | } |
| 2526 | break; |
| 2527 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2528 | case Primitive::kPrimLong: |
| 2529 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2530 | case Primitive::kPrimBoolean: |
| 2531 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2532 | case Primitive::kPrimByte: |
| 2533 | case Primitive::kPrimShort: |
| 2534 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2535 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2536 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2537 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2538 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2539 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2540 | __ cdq(); |
| 2541 | break; |
| 2542 | |
| 2543 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2544 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2545 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2546 | conversion, |
| 2547 | conversion->GetDexPc(), |
| 2548 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2549 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2550 | break; |
| 2551 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2552 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2553 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2554 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2555 | conversion, |
| 2556 | conversion->GetDexPc(), |
| 2557 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2558 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2559 | break; |
| 2560 | |
| 2561 | default: |
| 2562 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2563 | << " to " << result_type; |
| 2564 | } |
| 2565 | break; |
| 2566 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2567 | case Primitive::kPrimChar: |
| 2568 | switch (input_type) { |
Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2569 | case Primitive::kPrimLong: |
| 2570 | // Type conversion from long to short is a result of code transformations. |
| 2571 | if (in.IsRegisterPair()) { |
| 2572 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
| 2573 | } else if (in.IsDoubleStackSlot()) { |
| 2574 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
| 2575 | } else { |
| 2576 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2577 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
| 2578 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
| 2579 | } |
| 2580 | break; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2581 | case Primitive::kPrimBoolean: |
| 2582 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2583 | case Primitive::kPrimByte: |
| 2584 | case Primitive::kPrimShort: |
| 2585 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2586 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2587 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2588 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2589 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2590 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2591 | } else { |
| 2592 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2593 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2594 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2595 | } |
| 2596 | break; |
| 2597 | |
| 2598 | default: |
| 2599 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2600 | << " to " << result_type; |
| 2601 | } |
| 2602 | break; |
| 2603 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2604 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2605 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2606 | case Primitive::kPrimBoolean: |
| 2607 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2608 | case Primitive::kPrimByte: |
| 2609 | case Primitive::kPrimShort: |
| 2610 | case Primitive::kPrimInt: |
| 2611 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2612 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2613 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2614 | break; |
| 2615 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2616 | case Primitive::kPrimLong: { |
| 2617 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2618 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2619 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2620 | // Create stack space for the call to |
| 2621 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2622 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2623 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2624 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2625 | __ subl(ESP, Immediate(adjustment)); |
| 2626 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2627 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2628 | // Load the value to the FP stack, using temporaries if needed. |
| 2629 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2630 | |
| 2631 | if (out.IsStackSlot()) { |
| 2632 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2633 | } else { |
| 2634 | __ fstps(Address(ESP, 0)); |
| 2635 | Location stack_temp = Location::StackSlot(0); |
| 2636 | codegen_->Move32(out, stack_temp); |
| 2637 | } |
| 2638 | |
| 2639 | // Remove the temporary stack space we allocated. |
| 2640 | if (adjustment != 0) { |
| 2641 | __ addl(ESP, Immediate(adjustment)); |
| 2642 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2643 | break; |
| 2644 | } |
| 2645 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2646 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2647 | // Processing a Dex `double-to-float' instruction. |
| 2648 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2649 | break; |
| 2650 | |
| 2651 | default: |
| 2652 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2653 | << " to " << result_type; |
| 2654 | }; |
| 2655 | break; |
| 2656 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2657 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2658 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2659 | case Primitive::kPrimBoolean: |
| 2660 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2661 | case Primitive::kPrimByte: |
| 2662 | case Primitive::kPrimShort: |
| 2663 | case Primitive::kPrimInt: |
| 2664 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2665 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2666 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2667 | break; |
| 2668 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2669 | case Primitive::kPrimLong: { |
| 2670 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2671 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2672 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2673 | // Create stack space for the call to |
| 2674 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2675 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2676 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2677 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2678 | __ subl(ESP, Immediate(adjustment)); |
| 2679 | } |
| 2680 | |
| 2681 | // Load the value to the FP stack, using temporaries if needed. |
| 2682 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2683 | |
| 2684 | if (out.IsDoubleStackSlot()) { |
| 2685 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2686 | } else { |
| 2687 | __ fstpl(Address(ESP, 0)); |
| 2688 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2689 | codegen_->Move64(out, stack_temp); |
| 2690 | } |
| 2691 | |
| 2692 | // Remove the temporary stack space we allocated. |
| 2693 | if (adjustment != 0) { |
| 2694 | __ addl(ESP, Immediate(adjustment)); |
| 2695 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2696 | break; |
| 2697 | } |
| 2698 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2699 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2700 | // Processing a Dex `float-to-double' instruction. |
| 2701 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2702 | break; |
| 2703 | |
| 2704 | default: |
| 2705 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2706 | << " to " << result_type; |
| 2707 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2708 | break; |
| 2709 | |
| 2710 | default: |
| 2711 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2712 | << " to " << result_type; |
| 2713 | } |
| 2714 | } |
| 2715 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2716 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2717 | LocationSummary* locations = |
| 2718 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2719 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2720 | case Primitive::kPrimInt: { |
| 2721 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2722 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2723 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2724 | break; |
| 2725 | } |
| 2726 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2727 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2728 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2729 | locations->SetInAt(1, Location::Any()); |
| 2730 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2731 | break; |
| 2732 | } |
| 2733 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2734 | case Primitive::kPrimFloat: |
| 2735 | case Primitive::kPrimDouble: { |
| 2736 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2737 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2738 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2739 | } else if (add->InputAt(1)->IsConstant()) { |
| 2740 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2741 | } else { |
| 2742 | locations->SetInAt(1, Location::Any()); |
| 2743 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2744 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2745 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2746 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2747 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2748 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2749 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2750 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2751 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2755 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2756 | Location first = locations->InAt(0); |
| 2757 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2758 | Location out = locations->Out(); |
| 2759 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2760 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2761 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2762 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2763 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2764 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2765 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2766 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2767 | } else { |
| 2768 | __ leal(out.AsRegister<Register>(), Address( |
| 2769 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2770 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2771 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2772 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2773 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2774 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2775 | } else { |
| 2776 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2777 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2778 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2779 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2780 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2781 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2782 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2786 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2787 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2788 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2789 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2790 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2791 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2792 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2793 | } else { |
| 2794 | DCHECK(second.IsConstant()) << second; |
| 2795 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2796 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2797 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2798 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2799 | break; |
| 2800 | } |
| 2801 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2802 | case Primitive::kPrimFloat: { |
| 2803 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2804 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2805 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2806 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2807 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2808 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2809 | codegen_->LiteralFloatAddress( |
| 2810 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2811 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2812 | } else { |
| 2813 | DCHECK(second.IsStackSlot()); |
| 2814 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2815 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2816 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | case Primitive::kPrimDouble: { |
| 2820 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2821 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2822 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2823 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2824 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2825 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2826 | codegen_->LiteralDoubleAddress( |
| 2827 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2828 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2829 | } else { |
| 2830 | DCHECK(second.IsDoubleStackSlot()); |
| 2831 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2832 | } |
| 2833 | break; |
| 2834 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2835 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2836 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2837 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2838 | } |
| 2839 | } |
| 2840 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2841 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2842 | LocationSummary* locations = |
| 2843 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2844 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2845 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2846 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2847 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2848 | locations->SetInAt(1, Location::Any()); |
| 2849 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2850 | break; |
| 2851 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2852 | case Primitive::kPrimFloat: |
| 2853 | case Primitive::kPrimDouble: { |
| 2854 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2855 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2856 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2857 | } else if (sub->InputAt(1)->IsConstant()) { |
| 2858 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2859 | } else { |
| 2860 | locations->SetInAt(1, Location::Any()); |
| 2861 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2862 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2863 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2864 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2865 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2866 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2867 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2868 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2869 | } |
| 2870 | |
| 2871 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2872 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2873 | Location first = locations->InAt(0); |
| 2874 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2875 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2876 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2877 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2878 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2879 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2880 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2881 | __ subl(first.AsRegister<Register>(), |
| 2882 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2883 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2884 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2885 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2886 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2890 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2891 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2892 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2893 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2894 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2895 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2896 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2897 | } else { |
| 2898 | DCHECK(second.IsConstant()) << second; |
| 2899 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2900 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2901 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2902 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2903 | break; |
| 2904 | } |
| 2905 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2906 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2907 | if (second.IsFpuRegister()) { |
| 2908 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2909 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2910 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2911 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2912 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2913 | codegen_->LiteralFloatAddress( |
| 2914 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2915 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2916 | } else { |
| 2917 | DCHECK(second.IsStackSlot()); |
| 2918 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2919 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2920 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2924 | if (second.IsFpuRegister()) { |
| 2925 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2926 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2927 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2928 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2929 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2930 | codegen_->LiteralDoubleAddress( |
| 2931 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2932 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2933 | } else { |
| 2934 | DCHECK(second.IsDoubleStackSlot()); |
| 2935 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2936 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2937 | break; |
| 2938 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2939 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2940 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2941 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2942 | } |
| 2943 | } |
| 2944 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2945 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2946 | LocationSummary* locations = |
| 2947 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2948 | switch (mul->GetResultType()) { |
| 2949 | case Primitive::kPrimInt: |
| 2950 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2951 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2952 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2953 | // Can use 3 operand multiply. |
| 2954 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2955 | } else { |
| 2956 | locations->SetOut(Location::SameAsFirstInput()); |
| 2957 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2958 | break; |
| 2959 | case Primitive::kPrimLong: { |
| 2960 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2961 | locations->SetInAt(1, Location::Any()); |
| 2962 | locations->SetOut(Location::SameAsFirstInput()); |
| 2963 | // Needed for imul on 32bits with 64bits output. |
| 2964 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2965 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2966 | break; |
| 2967 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2968 | case Primitive::kPrimFloat: |
| 2969 | case Primitive::kPrimDouble: { |
| 2970 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2971 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2972 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2973 | } else if (mul->InputAt(1)->IsConstant()) { |
| 2974 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2975 | } else { |
| 2976 | locations->SetInAt(1, Location::Any()); |
| 2977 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2978 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2979 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2980 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2981 | |
| 2982 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2983 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2988 | LocationSummary* locations = mul->GetLocations(); |
| 2989 | Location first = locations->InAt(0); |
| 2990 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2991 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2992 | |
| 2993 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2994 | case Primitive::kPrimInt: |
| 2995 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2996 | // problems where the output may not be the same as the first operand. |
| 2997 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2998 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2999 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 3000 | } else if (second.IsRegister()) { |
| 3001 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3002 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3003 | } else { |
| 3004 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3005 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3006 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3007 | } |
| 3008 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3009 | |
| 3010 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3011 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 3012 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3013 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 3014 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3015 | |
| 3016 | DCHECK_EQ(EAX, eax); |
| 3017 | DCHECK_EQ(EDX, edx); |
| 3018 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3019 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3020 | // output: in1 |
| 3021 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 3022 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 3023 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3024 | if (second.IsConstant()) { |
| 3025 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3026 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3027 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 3028 | int32_t low_value = Low32Bits(value); |
| 3029 | int32_t high_value = High32Bits(value); |
| 3030 | Immediate low(low_value); |
| 3031 | Immediate high(high_value); |
| 3032 | |
| 3033 | __ movl(eax, high); |
| 3034 | // eax <- in1.lo * in2.hi |
| 3035 | __ imull(eax, in1_lo); |
| 3036 | // in1.hi <- in1.hi * in2.lo |
| 3037 | __ imull(in1_hi, low); |
| 3038 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3039 | __ addl(in1_hi, eax); |
| 3040 | // move in2_lo to eax to prepare for double precision |
| 3041 | __ movl(eax, low); |
| 3042 | // edx:eax <- in1.lo * in2.lo |
| 3043 | __ mull(in1_lo); |
| 3044 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3045 | __ addl(in1_hi, edx); |
| 3046 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3047 | __ movl(in1_lo, eax); |
| 3048 | } else if (second.IsRegisterPair()) { |
| 3049 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 3050 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 3051 | |
| 3052 | __ movl(eax, in2_hi); |
| 3053 | // eax <- in1.lo * in2.hi |
| 3054 | __ imull(eax, in1_lo); |
| 3055 | // in1.hi <- in1.hi * in2.lo |
| 3056 | __ imull(in1_hi, in2_lo); |
| 3057 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3058 | __ addl(in1_hi, eax); |
| 3059 | // move in1_lo to eax to prepare for double precision |
| 3060 | __ movl(eax, in1_lo); |
| 3061 | // edx:eax <- in1.lo * in2.lo |
| 3062 | __ mull(in2_lo); |
| 3063 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3064 | __ addl(in1_hi, edx); |
| 3065 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3066 | __ movl(in1_lo, eax); |
| 3067 | } else { |
| 3068 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 3069 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 3070 | Address in2_lo(ESP, second.GetStackIndex()); |
| 3071 | |
| 3072 | __ movl(eax, in2_hi); |
| 3073 | // eax <- in1.lo * in2.hi |
| 3074 | __ imull(eax, in1_lo); |
| 3075 | // in1.hi <- in1.hi * in2.lo |
| 3076 | __ imull(in1_hi, in2_lo); |
| 3077 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 3078 | __ addl(in1_hi, eax); |
| 3079 | // move in1_lo to eax to prepare for double precision |
| 3080 | __ movl(eax, in1_lo); |
| 3081 | // edx:eax <- in1.lo * in2.lo |
| 3082 | __ mull(in2_lo); |
| 3083 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 3084 | __ addl(in1_hi, edx); |
| 3085 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 3086 | __ movl(in1_lo, eax); |
| 3087 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3088 | |
| 3089 | break; |
| 3090 | } |
| 3091 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3092 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3093 | DCHECK(first.Equals(locations->Out())); |
| 3094 | if (second.IsFpuRegister()) { |
| 3095 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3096 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3097 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3098 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3099 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 3100 | codegen_->LiteralFloatAddress( |
| 3101 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3102 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3103 | } else { |
| 3104 | DCHECK(second.IsStackSlot()); |
| 3105 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3106 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3107 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3111 | DCHECK(first.Equals(locations->Out())); |
| 3112 | if (second.IsFpuRegister()) { |
| 3113 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3114 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3115 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3116 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3117 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 3118 | codegen_->LiteralDoubleAddress( |
| 3119 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3120 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3121 | } else { |
| 3122 | DCHECK(second.IsDoubleStackSlot()); |
| 3123 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3124 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3125 | break; |
| 3126 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3127 | |
| 3128 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3129 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3130 | } |
| 3131 | } |
| 3132 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3133 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 3134 | uint32_t temp_offset, |
| 3135 | uint32_t stack_adjustment, |
| 3136 | bool is_fp, |
| 3137 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3138 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3139 | DCHECK(!is_wide); |
| 3140 | if (is_fp) { |
| 3141 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3142 | } else { |
| 3143 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3144 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3145 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3146 | DCHECK(is_wide); |
| 3147 | if (is_fp) { |
| 3148 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3149 | } else { |
| 3150 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 3151 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3152 | } else { |
| 3153 | // 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] | 3154 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3155 | Location stack_temp = Location::StackSlot(temp_offset); |
| 3156 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3157 | if (is_fp) { |
| 3158 | __ flds(Address(ESP, temp_offset)); |
| 3159 | } else { |
| 3160 | __ filds(Address(ESP, temp_offset)); |
| 3161 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3162 | } else { |
| 3163 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 3164 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3165 | if (is_fp) { |
| 3166 | __ fldl(Address(ESP, temp_offset)); |
| 3167 | } else { |
| 3168 | __ fildl(Address(ESP, temp_offset)); |
| 3169 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3170 | } |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 3175 | Primitive::Type type = rem->GetResultType(); |
| 3176 | bool is_float = type == Primitive::kPrimFloat; |
| 3177 | size_t elem_size = Primitive::ComponentSize(type); |
| 3178 | LocationSummary* locations = rem->GetLocations(); |
| 3179 | Location first = locations->InAt(0); |
| 3180 | Location second = locations->InAt(1); |
| 3181 | Location out = locations->Out(); |
| 3182 | |
| 3183 | // Create stack space for 2 elements. |
| 3184 | // TODO: enhance register allocator to ask for stack temporaries. |
| 3185 | __ subl(ESP, Immediate(2 * elem_size)); |
| 3186 | |
| 3187 | // 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] | 3188 | const bool is_wide = !is_float; |
| 3189 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 3190 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3191 | |
| 3192 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3193 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3194 | __ Bind(&retry); |
| 3195 | __ fprem(); |
| 3196 | |
| 3197 | // Move FP status to AX. |
| 3198 | __ fstsw(); |
| 3199 | |
| 3200 | // And see if the argument reduction is complete. This is signaled by the |
| 3201 | // C2 FPU flag bit set to 0. |
| 3202 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 3203 | __ j(kNotEqual, &retry); |
| 3204 | |
| 3205 | // We have settled on the final value. Retrieve it into an XMM register. |
| 3206 | // Store FP top of stack to real stack. |
| 3207 | if (is_float) { |
| 3208 | __ fsts(Address(ESP, 0)); |
| 3209 | } else { |
| 3210 | __ fstl(Address(ESP, 0)); |
| 3211 | } |
| 3212 | |
| 3213 | // Pop the 2 items from the FP stack. |
| 3214 | __ fucompp(); |
| 3215 | |
| 3216 | // Load the value from the stack into an XMM register. |
| 3217 | DCHECK(out.IsFpuRegister()) << out; |
| 3218 | if (is_float) { |
| 3219 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3220 | } else { |
| 3221 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 3222 | } |
| 3223 | |
| 3224 | // And remove the temporary stack space we allocated. |
| 3225 | __ addl(ESP, Immediate(2 * elem_size)); |
| 3226 | } |
| 3227 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3228 | |
| 3229 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 3230 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3231 | |
| 3232 | LocationSummary* locations = instruction->GetLocations(); |
| 3233 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3234 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3235 | |
| 3236 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3237 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3238 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3239 | |
| 3240 | DCHECK(imm == 1 || imm == -1); |
| 3241 | |
| 3242 | if (instruction->IsRem()) { |
| 3243 | __ xorl(out_register, out_register); |
| 3244 | } else { |
| 3245 | __ movl(out_register, input_register); |
| 3246 | if (imm == -1) { |
| 3247 | __ negl(out_register); |
| 3248 | } |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3253 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3254 | LocationSummary* locations = instruction->GetLocations(); |
| 3255 | |
| 3256 | Register out_register = locations->Out().AsRegister<Register>(); |
| 3257 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3258 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3259 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); |
| 3260 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3261 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3262 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 3263 | |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3264 | __ leal(num, Address(input_register, abs_imm - 1)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3265 | __ testl(input_register, input_register); |
| 3266 | __ cmovl(kGreaterEqual, num, input_register); |
| 3267 | int shift = CTZ(imm); |
| 3268 | __ sarl(num, Immediate(shift)); |
| 3269 | |
| 3270 | if (imm < 0) { |
| 3271 | __ negl(num); |
| 3272 | } |
| 3273 | |
| 3274 | __ movl(out_register, num); |
| 3275 | } |
| 3276 | |
| 3277 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 3278 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3279 | |
| 3280 | LocationSummary* locations = instruction->GetLocations(); |
| 3281 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 3282 | |
| 3283 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 3284 | Register out = locations->Out().AsRegister<Register>(); |
| 3285 | Register num; |
| 3286 | Register edx; |
| 3287 | |
| 3288 | if (instruction->IsDiv()) { |
| 3289 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 3290 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 3291 | } else { |
| 3292 | edx = locations->Out().AsRegister<Register>(); |
| 3293 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 3294 | } |
| 3295 | |
| 3296 | DCHECK_EQ(EAX, eax); |
| 3297 | DCHECK_EQ(EDX, edx); |
| 3298 | if (instruction->IsDiv()) { |
| 3299 | DCHECK_EQ(EAX, out); |
| 3300 | } else { |
| 3301 | DCHECK_EQ(EDX, out); |
| 3302 | } |
| 3303 | |
| 3304 | int64_t magic; |
| 3305 | int shift; |
| 3306 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 3307 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3308 | // Save the numerator. |
| 3309 | __ movl(num, eax); |
| 3310 | |
| 3311 | // EAX = magic |
| 3312 | __ movl(eax, Immediate(magic)); |
| 3313 | |
| 3314 | // EDX:EAX = magic * numerator |
| 3315 | __ imull(num); |
| 3316 | |
| 3317 | if (imm > 0 && magic < 0) { |
| 3318 | // EDX += num |
| 3319 | __ addl(edx, num); |
| 3320 | } else if (imm < 0 && magic > 0) { |
| 3321 | __ subl(edx, num); |
| 3322 | } |
| 3323 | |
| 3324 | // Shift if needed. |
| 3325 | if (shift != 0) { |
| 3326 | __ sarl(edx, Immediate(shift)); |
| 3327 | } |
| 3328 | |
| 3329 | // EDX += 1 if EDX < 0 |
| 3330 | __ movl(eax, edx); |
| 3331 | __ shrl(edx, Immediate(31)); |
| 3332 | __ addl(edx, eax); |
| 3333 | |
| 3334 | if (instruction->IsRem()) { |
| 3335 | __ movl(eax, num); |
| 3336 | __ imull(edx, Immediate(imm)); |
| 3337 | __ subl(eax, edx); |
| 3338 | __ movl(edx, eax); |
| 3339 | } else { |
| 3340 | __ movl(eax, edx); |
| 3341 | } |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3342 | } |
| 3343 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3344 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 3345 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 3346 | |
| 3347 | LocationSummary* locations = instruction->GetLocations(); |
| 3348 | Location out = locations->Out(); |
| 3349 | Location first = locations->InAt(0); |
| 3350 | Location second = locations->InAt(1); |
| 3351 | bool is_div = instruction->IsDiv(); |
| 3352 | |
| 3353 | switch (instruction->GetResultType()) { |
| 3354 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3355 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 3356 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3357 | |
Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3358 | if (second.IsConstant()) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3359 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3360 | |
| 3361 | if (imm == 0) { |
| 3362 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 3363 | } else if (imm == 1 || imm == -1) { |
| 3364 | DivRemOneOrMinusOne(instruction); |
Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3365 | } else if (is_div && IsPowerOfTwo(AbsOrMin(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3366 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3367 | } else { |
| 3368 | DCHECK(imm <= -2 || imm >= 2); |
| 3369 | GenerateDivRemWithAnyConstant(instruction); |
| 3370 | } |
| 3371 | } else { |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3372 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86( |
| 3373 | instruction, out.AsRegister<Register>(), is_div); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3374 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3375 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3376 | Register second_reg = second.AsRegister<Register>(); |
| 3377 | // 0x80000000/-1 triggers an arithmetic exception! |
| 3378 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 3379 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3380 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3381 | __ cmpl(second_reg, Immediate(-1)); |
| 3382 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3383 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3384 | // edx:eax <- sign-extended of eax |
| 3385 | __ cdq(); |
| 3386 | // eax = quotient, edx = remainder |
| 3387 | __ idivl(second_reg); |
| 3388 | __ Bind(slow_path->GetExitLabel()); |
| 3389 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3390 | break; |
| 3391 | } |
| 3392 | |
| 3393 | case Primitive::kPrimLong: { |
| 3394 | InvokeRuntimeCallingConvention calling_convention; |
| 3395 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 3396 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 3397 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 3398 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 3399 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 3400 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 3401 | |
| 3402 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3403 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 3404 | instruction, |
| 3405 | instruction->GetDexPc(), |
| 3406 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3407 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3408 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3409 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3410 | instruction, |
| 3411 | instruction->GetDexPc(), |
| 3412 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3413 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3414 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3415 | break; |
| 3416 | } |
| 3417 | |
| 3418 | default: |
| 3419 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3420 | } |
| 3421 | } |
| 3422 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3423 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3424 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3425 | ? LocationSummary::kCall |
| 3426 | : LocationSummary::kNoCall; |
| 3427 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3428 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3429 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3430 | case Primitive::kPrimInt: { |
| 3431 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3432 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3433 | locations->SetOut(Location::SameAsFirstInput()); |
| 3434 | // Intel uses edx:eax as the dividend. |
| 3435 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3436 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3437 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3438 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3439 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3440 | locations->AddTemp(Location::RequiresRegister()); |
| 3441 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3442 | break; |
| 3443 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3444 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3445 | InvokeRuntimeCallingConvention calling_convention; |
| 3446 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3447 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3448 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3449 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3450 | // Runtime helper puts the result in EAX, EDX. |
| 3451 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3452 | break; |
| 3453 | } |
| 3454 | case Primitive::kPrimFloat: |
| 3455 | case Primitive::kPrimDouble: { |
| 3456 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3457 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3458 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); |
Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3459 | } else if (div->InputAt(1)->IsConstant()) { |
| 3460 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3461 | } else { |
| 3462 | locations->SetInAt(1, Location::Any()); |
| 3463 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3464 | locations->SetOut(Location::SameAsFirstInput()); |
| 3465 | break; |
| 3466 | } |
| 3467 | |
| 3468 | default: |
| 3469 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3474 | LocationSummary* locations = div->GetLocations(); |
| 3475 | Location first = locations->InAt(0); |
| 3476 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3477 | |
| 3478 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3479 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3480 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3481 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3482 | break; |
| 3483 | } |
| 3484 | |
| 3485 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3486 | if (second.IsFpuRegister()) { |
| 3487 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3488 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3489 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3490 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3491 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3492 | codegen_->LiteralFloatAddress( |
| 3493 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3494 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3495 | } else { |
| 3496 | DCHECK(second.IsStackSlot()); |
| 3497 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3498 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3499 | break; |
| 3500 | } |
| 3501 | |
| 3502 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3503 | if (second.IsFpuRegister()) { |
| 3504 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3505 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3506 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3507 | DCHECK(const_area->IsEmittedAtUseSite()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3508 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3509 | codegen_->LiteralDoubleAddress( |
| 3510 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3511 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3512 | } else { |
| 3513 | DCHECK(second.IsDoubleStackSlot()); |
| 3514 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3515 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3516 | break; |
| 3517 | } |
| 3518 | |
| 3519 | default: |
| 3520 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3521 | } |
| 3522 | } |
| 3523 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3524 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3525 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3526 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3527 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3528 | ? LocationSummary::kCall |
| 3529 | : LocationSummary::kNoCall; |
| 3530 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3531 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3532 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3533 | case Primitive::kPrimInt: { |
| 3534 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3535 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3536 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3537 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3538 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3539 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3540 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3541 | locations->AddTemp(Location::RequiresRegister()); |
| 3542 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3543 | break; |
| 3544 | } |
| 3545 | case Primitive::kPrimLong: { |
| 3546 | InvokeRuntimeCallingConvention calling_convention; |
| 3547 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3548 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3549 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3550 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3551 | // Runtime helper puts the result in EAX, EDX. |
| 3552 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3553 | break; |
| 3554 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3555 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3556 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3557 | locations->SetInAt(0, Location::Any()); |
| 3558 | locations->SetInAt(1, Location::Any()); |
| 3559 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3560 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3561 | break; |
| 3562 | } |
| 3563 | |
| 3564 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3565 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3566 | } |
| 3567 | } |
| 3568 | |
| 3569 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3570 | Primitive::Type type = rem->GetResultType(); |
| 3571 | switch (type) { |
| 3572 | case Primitive::kPrimInt: |
| 3573 | case Primitive::kPrimLong: { |
| 3574 | GenerateDivRemIntegral(rem); |
| 3575 | break; |
| 3576 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3577 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3578 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3579 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3580 | break; |
| 3581 | } |
| 3582 | default: |
| 3583 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3584 | } |
| 3585 | } |
| 3586 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3587 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3588 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3589 | ? LocationSummary::kCallOnSlowPath |
| 3590 | : LocationSummary::kNoCall; |
| 3591 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3592 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3593 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3594 | case Primitive::kPrimByte: |
| 3595 | case Primitive::kPrimChar: |
| 3596 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3597 | case Primitive::kPrimInt: { |
| 3598 | locations->SetInAt(0, Location::Any()); |
| 3599 | break; |
| 3600 | } |
| 3601 | case Primitive::kPrimLong: { |
| 3602 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3603 | if (!instruction->IsConstant()) { |
| 3604 | locations->AddTemp(Location::RequiresRegister()); |
| 3605 | } |
| 3606 | break; |
| 3607 | } |
| 3608 | default: |
| 3609 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3610 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3611 | if (instruction->HasUses()) { |
| 3612 | locations->SetOut(Location::SameAsFirstInput()); |
| 3613 | } |
| 3614 | } |
| 3615 | |
| 3616 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3617 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3618 | codegen_->AddSlowPath(slow_path); |
| 3619 | |
| 3620 | LocationSummary* locations = instruction->GetLocations(); |
| 3621 | Location value = locations->InAt(0); |
| 3622 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3623 | switch (instruction->GetType()) { |
Nicolas Geoffray | e567161 | 2016-03-16 11:03:54 +0000 | [diff] [blame] | 3624 | case Primitive::kPrimBoolean: |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3625 | case Primitive::kPrimByte: |
| 3626 | case Primitive::kPrimChar: |
| 3627 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3628 | case Primitive::kPrimInt: { |
| 3629 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3630 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3631 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3632 | } else if (value.IsStackSlot()) { |
| 3633 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3634 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3635 | } else { |
| 3636 | DCHECK(value.IsConstant()) << value; |
| 3637 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3638 | __ jmp(slow_path->GetEntryLabel()); |
| 3639 | } |
| 3640 | } |
| 3641 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3642 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3643 | case Primitive::kPrimLong: { |
| 3644 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3645 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3646 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3647 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3648 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3649 | } else { |
| 3650 | DCHECK(value.IsConstant()) << value; |
| 3651 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3652 | __ jmp(slow_path->GetEntryLabel()); |
| 3653 | } |
| 3654 | } |
| 3655 | break; |
| 3656 | } |
| 3657 | default: |
| 3658 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3659 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3660 | } |
| 3661 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3662 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3663 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3664 | |
| 3665 | LocationSummary* locations = |
| 3666 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3667 | |
| 3668 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3669 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3670 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3671 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3672 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3673 | // The shift count needs to be in CL or a constant. |
| 3674 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3675 | locations->SetOut(Location::SameAsFirstInput()); |
| 3676 | break; |
| 3677 | } |
| 3678 | default: |
| 3679 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3684 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3685 | |
| 3686 | LocationSummary* locations = op->GetLocations(); |
| 3687 | Location first = locations->InAt(0); |
| 3688 | Location second = locations->InAt(1); |
| 3689 | DCHECK(first.Equals(locations->Out())); |
| 3690 | |
| 3691 | switch (op->GetResultType()) { |
| 3692 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3693 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3694 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3695 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3696 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3697 | DCHECK_EQ(ECX, second_reg); |
| 3698 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3699 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3700 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3701 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3702 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3703 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3704 | } |
| 3705 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3706 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3707 | if (shift == 0) { |
| 3708 | return; |
| 3709 | } |
| 3710 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3711 | if (op->IsShl()) { |
| 3712 | __ shll(first_reg, imm); |
| 3713 | } else if (op->IsShr()) { |
| 3714 | __ sarl(first_reg, imm); |
| 3715 | } else { |
| 3716 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3717 | } |
| 3718 | } |
| 3719 | break; |
| 3720 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3721 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3722 | if (second.IsRegister()) { |
| 3723 | Register second_reg = second.AsRegister<Register>(); |
| 3724 | DCHECK_EQ(ECX, second_reg); |
| 3725 | if (op->IsShl()) { |
| 3726 | GenerateShlLong(first, second_reg); |
| 3727 | } else if (op->IsShr()) { |
| 3728 | GenerateShrLong(first, second_reg); |
| 3729 | } else { |
| 3730 | GenerateUShrLong(first, second_reg); |
| 3731 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3732 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3733 | // Shift by a constant. |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3734 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3735 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3736 | if (shift != 0) { |
| 3737 | if (op->IsShl()) { |
| 3738 | GenerateShlLong(first, shift); |
| 3739 | } else if (op->IsShr()) { |
| 3740 | GenerateShrLong(first, shift); |
| 3741 | } else { |
| 3742 | GenerateUShrLong(first, shift); |
| 3743 | } |
| 3744 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3745 | } |
| 3746 | break; |
| 3747 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3748 | default: |
| 3749 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3750 | } |
| 3751 | } |
| 3752 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3753 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3754 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3755 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3756 | if (shift == 1) { |
| 3757 | // This is just an addition. |
| 3758 | __ addl(low, low); |
| 3759 | __ adcl(high, high); |
| 3760 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3761 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3762 | codegen_->EmitParallelMoves( |
| 3763 | loc.ToLow(), |
| 3764 | loc.ToHigh(), |
| 3765 | Primitive::kPrimInt, |
| 3766 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3767 | loc.ToLow(), |
| 3768 | Primitive::kPrimInt); |
| 3769 | } else if (shift > 32) { |
| 3770 | // Low part becomes 0. High part is low part << (shift-32). |
| 3771 | __ movl(high, low); |
| 3772 | __ shll(high, Immediate(shift - 32)); |
| 3773 | __ xorl(low, low); |
| 3774 | } else { |
| 3775 | // Between 1 and 31. |
| 3776 | __ shld(high, low, Immediate(shift)); |
| 3777 | __ shll(low, Immediate(shift)); |
| 3778 | } |
| 3779 | } |
| 3780 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3781 | void InstructionCodeGeneratorX86::GenerateShlLong(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 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3784 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3785 | __ testl(shifter, Immediate(32)); |
| 3786 | __ j(kEqual, &done); |
| 3787 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3788 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3789 | __ Bind(&done); |
| 3790 | } |
| 3791 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3792 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3793 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3794 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3795 | if (shift == 32) { |
| 3796 | // Need to copy the sign. |
| 3797 | DCHECK_NE(low, high); |
| 3798 | __ movl(low, high); |
| 3799 | __ sarl(high, Immediate(31)); |
| 3800 | } else if (shift > 32) { |
| 3801 | DCHECK_NE(low, high); |
| 3802 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3803 | __ movl(low, high); |
| 3804 | __ sarl(high, Immediate(31)); |
| 3805 | __ sarl(low, Immediate(shift - 32)); |
| 3806 | } else { |
| 3807 | // Between 1 and 31. |
| 3808 | __ shrd(low, high, Immediate(shift)); |
| 3809 | __ sarl(high, Immediate(shift)); |
| 3810 | } |
| 3811 | } |
| 3812 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3813 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3814 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3815 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3816 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3817 | __ testl(shifter, Immediate(32)); |
| 3818 | __ j(kEqual, &done); |
| 3819 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3820 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3821 | __ Bind(&done); |
| 3822 | } |
| 3823 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3824 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3825 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3826 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3827 | if (shift == 32) { |
| 3828 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3829 | codegen_->EmitParallelMoves( |
| 3830 | loc.ToHigh(), |
| 3831 | loc.ToLow(), |
| 3832 | Primitive::kPrimInt, |
| 3833 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3834 | loc.ToHigh(), |
| 3835 | Primitive::kPrimInt); |
| 3836 | } else if (shift > 32) { |
| 3837 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3838 | __ movl(low, high); |
| 3839 | __ shrl(low, Immediate(shift - 32)); |
| 3840 | __ xorl(high, high); |
| 3841 | } else { |
| 3842 | // Between 1 and 31. |
| 3843 | __ shrd(low, high, Immediate(shift)); |
| 3844 | __ shrl(high, Immediate(shift)); |
| 3845 | } |
| 3846 | } |
| 3847 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3848 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3849 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3850 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3851 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3852 | __ testl(shifter, Immediate(32)); |
| 3853 | __ j(kEqual, &done); |
| 3854 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3855 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3856 | __ Bind(&done); |
| 3857 | } |
| 3858 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3859 | void LocationsBuilderX86::VisitRor(HRor* ror) { |
| 3860 | LocationSummary* locations = |
| 3861 | new (GetGraph()->GetArena()) LocationSummary(ror, LocationSummary::kNoCall); |
| 3862 | |
| 3863 | switch (ror->GetResultType()) { |
| 3864 | case Primitive::kPrimLong: |
| 3865 | // Add the temporary needed. |
| 3866 | locations->AddTemp(Location::RequiresRegister()); |
| 3867 | FALLTHROUGH_INTENDED; |
| 3868 | case Primitive::kPrimInt: |
| 3869 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3870 | // The shift count needs to be in CL (unless it is a constant). |
| 3871 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); |
| 3872 | locations->SetOut(Location::SameAsFirstInput()); |
| 3873 | break; |
| 3874 | default: |
| 3875 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); |
| 3876 | UNREACHABLE(); |
| 3877 | } |
| 3878 | } |
| 3879 | |
| 3880 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { |
| 3881 | LocationSummary* locations = ror->GetLocations(); |
| 3882 | Location first = locations->InAt(0); |
| 3883 | Location second = locations->InAt(1); |
| 3884 | |
| 3885 | if (ror->GetResultType() == Primitive::kPrimInt) { |
| 3886 | Register first_reg = first.AsRegister<Register>(); |
| 3887 | if (second.IsRegister()) { |
| 3888 | Register second_reg = second.AsRegister<Register>(); |
| 3889 | __ rorl(first_reg, second_reg); |
| 3890 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3891 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3892 | __ rorl(first_reg, imm); |
| 3893 | } |
| 3894 | return; |
| 3895 | } |
| 3896 | |
| 3897 | DCHECK_EQ(ror->GetResultType(), Primitive::kPrimLong); |
| 3898 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); |
| 3899 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); |
| 3900 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 3901 | if (second.IsRegister()) { |
| 3902 | Register second_reg = second.AsRegister<Register>(); |
| 3903 | DCHECK_EQ(second_reg, ECX); |
| 3904 | __ movl(temp_reg, first_reg_hi); |
| 3905 | __ shrd(first_reg_hi, first_reg_lo, second_reg); |
| 3906 | __ shrd(first_reg_lo, temp_reg, second_reg); |
| 3907 | __ movl(temp_reg, first_reg_hi); |
| 3908 | __ testl(second_reg, Immediate(32)); |
| 3909 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); |
| 3910 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); |
| 3911 | } else { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3912 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 3913 | if (shift_amt == 0) { |
| 3914 | // Already fine. |
| 3915 | return; |
| 3916 | } |
| 3917 | if (shift_amt == 32) { |
| 3918 | // Just swap. |
| 3919 | __ movl(temp_reg, first_reg_lo); |
| 3920 | __ movl(first_reg_lo, first_reg_hi); |
| 3921 | __ movl(first_reg_hi, temp_reg); |
| 3922 | return; |
| 3923 | } |
| 3924 | |
| 3925 | Immediate imm(shift_amt); |
| 3926 | // Save the constents of the low value. |
| 3927 | __ movl(temp_reg, first_reg_lo); |
| 3928 | |
| 3929 | // Shift right into low, feeding bits from high. |
| 3930 | __ shrd(first_reg_lo, first_reg_hi, imm); |
| 3931 | |
| 3932 | // Shift right into high, feeding bits from the original low. |
| 3933 | __ shrd(first_reg_hi, temp_reg, imm); |
| 3934 | |
| 3935 | // Swap if needed. |
| 3936 | if (shift_amt > 32) { |
| 3937 | __ movl(temp_reg, first_reg_lo); |
| 3938 | __ movl(first_reg_lo, first_reg_hi); |
| 3939 | __ movl(first_reg_hi, temp_reg); |
| 3940 | } |
| 3941 | } |
| 3942 | } |
| 3943 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3944 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3945 | HandleShift(shl); |
| 3946 | } |
| 3947 | |
| 3948 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3949 | HandleShift(shl); |
| 3950 | } |
| 3951 | |
| 3952 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3953 | HandleShift(shr); |
| 3954 | } |
| 3955 | |
| 3956 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3957 | HandleShift(shr); |
| 3958 | } |
| 3959 | |
| 3960 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3961 | HandleShift(ushr); |
| 3962 | } |
| 3963 | |
| 3964 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3965 | HandleShift(ushr); |
| 3966 | } |
| 3967 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3968 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3969 | LocationSummary* locations = |
| 3970 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3971 | locations->SetOut(Location::RegisterLocation(EAX)); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3972 | if (instruction->IsStringAlloc()) { |
| 3973 | locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3974 | } else { |
| 3975 | InvokeRuntimeCallingConvention calling_convention; |
| 3976 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 3977 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 3978 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3982 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3983 | // of poisoning the reference. |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3984 | if (instruction->IsStringAlloc()) { |
| 3985 | // String is allocated through StringFactory. Call NewEmptyString entry point. |
| 3986 | Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>(); |
| 3987 | MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize); |
| 3988 | __ fs()->movl(temp, Address::Absolute(QUICK_ENTRY_POINT(pNewEmptyString))); |
| 3989 | __ call(Address(temp, code_offset.Int32Value())); |
| 3990 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 3991 | } else { |
| 3992 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3993 | instruction, |
| 3994 | instruction->GetDexPc(), |
| 3995 | nullptr); |
| 3996 | CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>(); |
| 3997 | DCHECK(!codegen_->IsLeafMethod()); |
| 3998 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3999 | } |
| 4000 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4001 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 4002 | LocationSummary* locations = |
| 4003 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 4004 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 4005 | InvokeRuntimeCallingConvention calling_convention; |
| 4006 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 4007 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4008 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4009 | } |
| 4010 | |
| 4011 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 4012 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4013 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4014 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 4015 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4016 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 4017 | instruction, |
| 4018 | instruction->GetDexPc(), |
| 4019 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 4020 | CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck, void*, uint32_t, int32_t, ArtMethod*>(); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4021 | DCHECK(!codegen_->IsLeafMethod()); |
| 4022 | } |
| 4023 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4024 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4025 | LocationSummary* locations = |
| 4026 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4027 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 4028 | if (location.IsStackSlot()) { |
| 4029 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 4030 | } else if (location.IsDoubleStackSlot()) { |
| 4031 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4032 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4033 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4034 | } |
| 4035 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4036 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 4037 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 4038 | } |
| 4039 | |
| 4040 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 4041 | LocationSummary* locations = |
| 4042 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4043 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 4044 | } |
| 4045 | |
| 4046 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4047 | } |
| 4048 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4049 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4050 | LocationSummary* locations = |
| 4051 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4052 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4053 | locations->SetOut(Location::RequiresRegister()); |
| 4054 | } |
| 4055 | |
| 4056 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { |
| 4057 | LocationSummary* locations = instruction->GetLocations(); |
| 4058 | uint32_t method_offset = 0; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4059 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4060 | method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4061 | instruction->GetIndex(), kX86PointerSize).SizeValue(); |
| 4062 | } else { |
| 4063 | method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 4064 | instruction->GetIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
| 4065 | } |
| 4066 | __ movl(locations->Out().AsRegister<Register>(), |
| 4067 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); |
| 4068 | } |
| 4069 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4070 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4071 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4072 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4073 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4074 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4075 | } |
| 4076 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4077 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 4078 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4079 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4080 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4081 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4082 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4083 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4084 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4085 | break; |
| 4086 | |
| 4087 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4088 | __ notl(out.AsRegisterPairLow<Register>()); |
| 4089 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4090 | break; |
| 4091 | |
| 4092 | default: |
| 4093 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 4094 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4095 | } |
| 4096 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4097 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 4098 | LocationSummary* locations = |
| 4099 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 4100 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4101 | locations->SetOut(Location::SameAsFirstInput()); |
| 4102 | } |
| 4103 | |
| 4104 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4105 | LocationSummary* locations = bool_not->GetLocations(); |
| 4106 | Location in = locations->InAt(0); |
| 4107 | Location out = locations->Out(); |
| 4108 | DCHECK(in.Equals(out)); |
| 4109 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 4110 | } |
| 4111 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4112 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4113 | LocationSummary* locations = |
| 4114 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4115 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4116 | case Primitive::kPrimBoolean: |
| 4117 | case Primitive::kPrimByte: |
| 4118 | case Primitive::kPrimShort: |
| 4119 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4120 | case Primitive::kPrimInt: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4121 | case Primitive::kPrimLong: { |
| 4122 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4123 | locations->SetInAt(1, Location::Any()); |
| 4124 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 4125 | break; |
| 4126 | } |
| 4127 | case Primitive::kPrimFloat: |
| 4128 | case Primitive::kPrimDouble: { |
| 4129 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4130 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 4131 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); |
| 4132 | } else if (compare->InputAt(1)->IsConstant()) { |
| 4133 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4134 | } else { |
| 4135 | locations->SetInAt(1, Location::Any()); |
| 4136 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4137 | locations->SetOut(Location::RequiresRegister()); |
| 4138 | break; |
| 4139 | } |
| 4140 | default: |
| 4141 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 4142 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4143 | } |
| 4144 | |
| 4145 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4146 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4147 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4148 | Location left = locations->InAt(0); |
| 4149 | Location right = locations->InAt(1); |
| 4150 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4151 | NearLabel less, greater, done; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4152 | Condition less_cond = kLess; |
| 4153 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4154 | switch (compare->InputAt(0)->GetType()) { |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4155 | case Primitive::kPrimBoolean: |
| 4156 | case Primitive::kPrimByte: |
| 4157 | case Primitive::kPrimShort: |
| 4158 | case Primitive::kPrimChar: |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4159 | case Primitive::kPrimInt: { |
Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 4160 | GenerateIntCompare(left, right); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4161 | break; |
| 4162 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4163 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4164 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 4165 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 4166 | int32_t val_low = 0; |
| 4167 | int32_t val_high = 0; |
| 4168 | bool right_is_const = false; |
| 4169 | |
| 4170 | if (right.IsConstant()) { |
| 4171 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 4172 | right_is_const = true; |
| 4173 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 4174 | val_low = Low32Bits(val); |
| 4175 | val_high = High32Bits(val); |
| 4176 | } |
| 4177 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4178 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4179 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4180 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4181 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4182 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4183 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4184 | codegen_->Compare32BitValue(left_high, val_high); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4185 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4186 | __ j(kLess, &less); // Signed compare. |
| 4187 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4188 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4189 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4190 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4191 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4192 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4193 | DCHECK(right_is_const) << right; |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4194 | codegen_->Compare32BitValue(left_low, val_low); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4195 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4196 | less_cond = kBelow; // for CF (unsigned). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4197 | break; |
| 4198 | } |
| 4199 | case Primitive::kPrimFloat: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4200 | GenerateFPCompare(left, right, compare, false); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4201 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4202 | less_cond = kBelow; // for CF (floats). |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4203 | break; |
| 4204 | } |
| 4205 | case Primitive::kPrimDouble: { |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4206 | GenerateFPCompare(left, right, compare, true); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4207 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4208 | less_cond = kBelow; // for CF (floats). |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4209 | break; |
| 4210 | } |
| 4211 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4212 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4213 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4214 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4215 | __ movl(out, Immediate(0)); |
| 4216 | __ j(kEqual, &done); |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4217 | __ j(less_cond, &less); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4218 | |
| 4219 | __ Bind(&greater); |
| 4220 | __ movl(out, Immediate(1)); |
| 4221 | __ jmp(&done); |
| 4222 | |
| 4223 | __ Bind(&less); |
| 4224 | __ movl(out, Immediate(-1)); |
| 4225 | |
| 4226 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4227 | } |
| 4228 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4229 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4230 | LocationSummary* locations = |
| 4231 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4232 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 4233 | locations->SetInAt(i, Location::Any()); |
| 4234 | } |
| 4235 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4236 | } |
| 4237 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4238 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4239 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4240 | } |
| 4241 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4242 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4243 | /* |
| 4244 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 4245 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 4246 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 4247 | */ |
| 4248 | switch (kind) { |
| 4249 | case MemBarrierKind::kAnyAny: { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4250 | MemoryFence(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4251 | break; |
| 4252 | } |
| 4253 | case MemBarrierKind::kAnyStore: |
| 4254 | case MemBarrierKind::kLoadAny: |
| 4255 | case MemBarrierKind::kStoreStore: { |
| 4256 | // nop |
| 4257 | break; |
| 4258 | } |
Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4259 | case MemBarrierKind::kNTStoreStore: |
| 4260 | // Non-Temporal Store/Store needs an explicit fence. |
| 4261 | MemoryFence(/* non-temporal */ true); |
| 4262 | break; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4263 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4264 | } |
| 4265 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4266 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( |
| 4267 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, |
| 4268 | MethodReference target_method ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4269 | HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info; |
| 4270 | |
| 4271 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 4272 | // is incompatible with it. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4273 | // TODO: Create as many X86ComputeBaseMethodAddress instructions |
| 4274 | // as needed for methods with irreducible loops. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4275 | if (GetGraph()->HasIrreducibleLoops() && |
| 4276 | (dispatch_info.method_load_kind == |
| 4277 | HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative)) { |
| 4278 | dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod; |
| 4279 | } |
| 4280 | switch (dispatch_info.code_ptr_location) { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4281 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4282 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 4283 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 4284 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 4285 | return HInvokeStaticOrDirect::DispatchInfo { |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4286 | dispatch_info.method_load_kind, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4287 | HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4288 | dispatch_info.method_load_data, |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4289 | 0u |
| 4290 | }; |
| 4291 | default: |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 4292 | return dispatch_info; |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4293 | } |
| 4294 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4295 | |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4296 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, |
| 4297 | Register temp) { |
| 4298 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4299 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4300 | if (!invoke->GetLocations()->Intrinsified()) { |
| 4301 | return location.AsRegister<Register>(); |
| 4302 | } |
| 4303 | // For intrinsics we allow any location, so it may be on the stack. |
| 4304 | if (!location.IsRegister()) { |
| 4305 | __ movl(temp, Address(ESP, location.GetStackIndex())); |
| 4306 | return temp; |
| 4307 | } |
| 4308 | // For register locations, check if the register was saved. If so, get it from the stack. |
| 4309 | // Note: There is a chance that the register was saved but not overwritten, so we could |
| 4310 | // save one load. However, since this is just an intrinsic slow path we prefer this |
| 4311 | // simple and more robust approach rather that trying to determine if that's the case. |
| 4312 | SlowPathCode* slow_path = GetCurrentSlowPath(); |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4313 | if (slow_path != nullptr) { |
| 4314 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { |
| 4315 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); |
| 4316 | __ movl(temp, Address(ESP, stack_offset)); |
| 4317 | return temp; |
| 4318 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4319 | } |
| 4320 | return location.AsRegister<Register>(); |
| 4321 | } |
| 4322 | |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4323 | Location CodeGeneratorX86::GenerateCalleeMethodStaticOrDirectCall(HInvokeStaticOrDirect* invoke, |
| 4324 | Location temp) { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4325 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 4326 | switch (invoke->GetMethodLoadKind()) { |
| 4327 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 4328 | // temp = thread->string_init_entrypoint |
| 4329 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 4330 | break; |
| 4331 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4332 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4333 | break; |
| 4334 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 4335 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 4336 | break; |
| 4337 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4338 | __ movl(temp.AsRegister<Register>(), Immediate(/* placeholder */ 0)); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4339 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4340 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 4341 | break; |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4342 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: { |
| 4343 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, |
| 4344 | temp.AsRegister<Register>()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4345 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4346 | // Bind a new fixup label at the end of the "movl" insn. |
| 4347 | uint32_t offset = invoke->GetDexCacheArrayOffset(); |
| 4348 | __ Bind(NewPcRelativeDexCacheArrayPatch(*invoke->GetTargetMethod().dex_file, offset)); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4349 | break; |
| 4350 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4351 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4352 | Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4353 | Register method_reg; |
| 4354 | Register reg = temp.AsRegister<Register>(); |
| 4355 | if (current_method.IsRegister()) { |
| 4356 | method_reg = current_method.AsRegister<Register>(); |
| 4357 | } else { |
David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 4358 | DCHECK(invoke->GetLocations()->Intrinsified()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4359 | DCHECK(!current_method.IsValid()); |
| 4360 | method_reg = reg; |
| 4361 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 4362 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4363 | // /* ArtMethod*[] */ temp = temp.ptr_sized_fields_->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4364 | __ movl(reg, Address(method_reg, |
| 4365 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 40ecb12 | 2016-04-06 17:33:41 +0100 | [diff] [blame] | 4366 | // temp = temp[index_in_cache]; |
| 4367 | // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file. |
| 4368 | uint32_t index_in_cache = invoke->GetDexMethodIndex(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4369 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 4370 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4371 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4372 | } |
Serguei Katkov | 288c7a8 | 2016-05-16 11:53:15 +0600 | [diff] [blame] | 4373 | return callee_method; |
| 4374 | } |
| 4375 | |
| 4376 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 4377 | Location callee_method = GenerateCalleeMethodStaticOrDirectCall(invoke, temp); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4378 | |
| 4379 | switch (invoke->GetCodePtrLocation()) { |
| 4380 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 4381 | __ call(GetFrameEntryLabel()); |
| 4382 | break; |
| 4383 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 4384 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 4385 | Label* label = &relative_call_patches_.back().label; |
| 4386 | __ call(label); // Bind to the patch label, override at link time. |
| 4387 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 4388 | break; |
| 4389 | } |
| 4390 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 4391 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4392 | // Filtered out by GetSupportedInvokeStaticOrDirectDispatch(). |
| 4393 | LOG(FATAL) << "Unsupported"; |
| 4394 | UNREACHABLE(); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4395 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 4396 | // (callee_method + offset_of_quick_compiled_code)() |
| 4397 | __ call(Address(callee_method.AsRegister<Register>(), |
| 4398 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 4399 | kX86WordSize).Int32Value())); |
| 4400 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4404 | } |
| 4405 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4406 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 4407 | Register temp = temp_in.AsRegister<Register>(); |
| 4408 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 4409 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4410 | |
| 4411 | // Use the calling convention instead of the location of the receiver, as |
| 4412 | // intrinsics may have put the receiver in a different register. In the intrinsics |
| 4413 | // slow path, the arguments have been moved to the right place, so here we are |
| 4414 | // guaranteed that the receiver is the first register of the calling convention. |
| 4415 | InvokeDexCallingConvention calling_convention; |
| 4416 | Register receiver = calling_convention.GetRegisterAt(0); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4417 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4418 | // /* HeapReference<Class> */ temp = receiver->klass_ |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4419 | __ movl(temp, Address(receiver, class_offset)); |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4420 | MaybeRecordImplicitNullCheck(invoke); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4421 | // Instead of simply (possibly) unpoisoning `temp` here, we should |
| 4422 | // emit a read barrier for the previous class reference load. |
| 4423 | // However this is not required in practice, as this is an |
| 4424 | // intermediate/temporary reference and because the current |
| 4425 | // concurrent copying collector keeps the from-space memory |
| 4426 | // intact/accessible until the end of the marking phase (the |
| 4427 | // concurrent copying collector may not in the future). |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4428 | __ MaybeUnpoisonHeapReference(temp); |
| 4429 | // temp = temp->GetMethodAt(method_offset); |
| 4430 | __ movl(temp, Address(temp, method_offset)); |
| 4431 | // call temp->GetEntryPoint(); |
| 4432 | __ call(Address( |
| 4433 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 4434 | } |
| 4435 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4436 | void CodeGeneratorX86::RecordSimplePatch() { |
| 4437 | if (GetCompilerOptions().GetIncludePatchInformation()) { |
| 4438 | simple_patches_.emplace_back(); |
| 4439 | __ Bind(&simple_patches_.back()); |
| 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | void CodeGeneratorX86::RecordStringPatch(HLoadString* load_string) { |
| 4444 | string_patches_.emplace_back(load_string->GetDexFile(), load_string->GetStringIndex()); |
| 4445 | __ Bind(&string_patches_.back().label); |
| 4446 | } |
| 4447 | |
| 4448 | Label* CodeGeneratorX86::NewPcRelativeDexCacheArrayPatch(const DexFile& dex_file, |
| 4449 | uint32_t element_offset) { |
| 4450 | // Add the patch entry and bind its label at the end of the instruction. |
| 4451 | pc_relative_dex_cache_patches_.emplace_back(dex_file, element_offset); |
| 4452 | return &pc_relative_dex_cache_patches_.back().label; |
| 4453 | } |
| 4454 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4455 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 4456 | DCHECK(linker_patches->empty()); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4457 | size_t size = |
| 4458 | method_patches_.size() + |
| 4459 | relative_call_patches_.size() + |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4460 | pc_relative_dex_cache_patches_.size() + |
| 4461 | simple_patches_.size() + |
| 4462 | string_patches_.size(); |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4463 | linker_patches->reserve(size); |
| 4464 | // The label points to the end of the "movl" insn but the literal offset for method |
| 4465 | // patch needs to point to the embedded constant which occupies the last 4 bytes. |
| 4466 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4467 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4468 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4469 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 4470 | info.target_method.dex_file, |
| 4471 | info.target_method.dex_method_index)); |
| 4472 | } |
| 4473 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4474 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4475 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 4476 | info.target_method.dex_file, |
| 4477 | info.target_method.dex_method_index)); |
| 4478 | } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4479 | for (const PcRelativeDexCacheAccessInfo& info : pc_relative_dex_cache_patches_) { |
| 4480 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4481 | linker_patches->push_back(LinkerPatch::DexCacheArrayPatch(literal_offset, |
| 4482 | &info.target_dex_file, |
| 4483 | GetMethodAddressOffset(), |
| 4484 | info.element_offset)); |
| 4485 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4486 | for (const Label& label : simple_patches_) { |
| 4487 | uint32_t literal_offset = label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4488 | linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset)); |
| 4489 | } |
| 4490 | if (GetCompilerOptions().GetCompilePic()) { |
| 4491 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4492 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4493 | linker_patches->push_back(LinkerPatch::RelativeStringPatch(literal_offset, |
| 4494 | &info.dex_file, |
| 4495 | GetMethodAddressOffset(), |
| 4496 | info.string_index)); |
| 4497 | } |
| 4498 | } else { |
| 4499 | for (const StringPatchInfo<Label>& info : string_patches_) { |
| 4500 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; |
| 4501 | linker_patches->push_back(LinkerPatch::StringPatch(literal_offset, |
| 4502 | &info.dex_file, |
| 4503 | info.string_index)); |
| 4504 | } |
| 4505 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4506 | } |
| 4507 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4508 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 4509 | Register card, |
| 4510 | Register object, |
| 4511 | Register value, |
| 4512 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4513 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4514 | if (value_can_be_null) { |
| 4515 | __ testl(value, value); |
| 4516 | __ j(kEqual, &is_null); |
| 4517 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4518 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 4519 | __ movl(temp, object); |
| 4520 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 4521 | __ movb(Address(temp, card, TIMES_1, 0), |
| 4522 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4523 | if (value_can_be_null) { |
| 4524 | __ Bind(&is_null); |
| 4525 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4526 | } |
| 4527 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4528 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4529 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4530 | |
| 4531 | bool object_field_get_with_read_barrier = |
| 4532 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4533 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4534 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 4535 | kEmitCompilerReadBarrier ? |
| 4536 | LocationSummary::kCallOnSlowPath : |
| 4537 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4538 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4539 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4540 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4541 | locations->SetOut(Location::RequiresFpuRegister()); |
| 4542 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4543 | // The output overlaps in case of long: we don't want the low move |
| 4544 | // to overwrite the object's location. Likewise, in the case of |
| 4545 | // an object field get with read barriers enabled, we do not want |
| 4546 | // the move to overwrite the object's location, as we need it to emit |
| 4547 | // the read barrier. |
| 4548 | locations->SetOut( |
| 4549 | Location::RequiresRegister(), |
| 4550 | (object_field_get_with_read_barrier || instruction->GetType() == Primitive::kPrimLong) ? |
| 4551 | Location::kOutputOverlap : |
| 4552 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4553 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4554 | |
| 4555 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 4556 | // Long values can be loaded atomically into an XMM using movsd. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4557 | // So we use an XMM register as a temp to achieve atomicity (first |
| 4558 | // load the temp into the XMM and then copy the XMM into the |
| 4559 | // output, 32 bits at a time). |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4560 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4561 | } else if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { |
| 4562 | // We need a temporary register for the read barrier marking slow |
| 4563 | // path in CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier. |
| 4564 | locations->AddTemp(Location::RequiresRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4565 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4566 | } |
| 4567 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4568 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 4569 | const FieldInfo& field_info) { |
| 4570 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4571 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4572 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4573 | Location base_loc = locations->InAt(0); |
| 4574 | Register base = base_loc.AsRegister<Register>(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4575 | Location out = locations->Out(); |
| 4576 | bool is_volatile = field_info.IsVolatile(); |
| 4577 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4578 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 4579 | |
| 4580 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4581 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4582 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4583 | break; |
| 4584 | } |
| 4585 | |
| 4586 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4587 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4588 | break; |
| 4589 | } |
| 4590 | |
| 4591 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4592 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4593 | break; |
| 4594 | } |
| 4595 | |
| 4596 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4597 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4598 | break; |
| 4599 | } |
| 4600 | |
| 4601 | case Primitive::kPrimInt: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4602 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4603 | break; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4604 | |
| 4605 | case Primitive::kPrimNot: { |
| 4606 | // /* HeapReference<Object> */ out = *(base + offset) |
| 4607 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 4608 | Location temp_loc = locations->GetTemp(0); |
| 4609 | // Note that a potential implicit null check is handled in this |
| 4610 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. |
| 4611 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 4612 | instruction, out, base, offset, temp_loc, /* needs_null_check */ true); |
| 4613 | if (is_volatile) { |
| 4614 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4615 | } |
| 4616 | } else { |
| 4617 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
| 4618 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4619 | if (is_volatile) { |
| 4620 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4621 | } |
| 4622 | // If read barriers are enabled, emit read barriers other than |
| 4623 | // Baker's using a slow path (and also unpoison the loaded |
| 4624 | // reference, if heap poisoning is enabled). |
| 4625 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); |
| 4626 | } |
| 4627 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4631 | if (is_volatile) { |
| 4632 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4633 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4634 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4635 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 4636 | __ psrlq(temp, Immediate(32)); |
| 4637 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 4638 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4639 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4640 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4641 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4642 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 4643 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4644 | break; |
| 4645 | } |
| 4646 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4647 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4648 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4649 | break; |
| 4650 | } |
| 4651 | |
| 4652 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4653 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 4654 | break; |
| 4655 | } |
| 4656 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4657 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4658 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4659 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4660 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4661 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4662 | if (field_type == Primitive::kPrimNot || field_type == Primitive::kPrimLong) { |
| 4663 | // Potential implicit null checks, in the case of reference or |
| 4664 | // long fields, are handled in the previous switch statement. |
| 4665 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4666 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4667 | } |
| 4668 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4669 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4670 | if (field_type == Primitive::kPrimNot) { |
| 4671 | // Memory barriers, in the case of references, are also handled |
| 4672 | // in the previous switch statement. |
| 4673 | } else { |
| 4674 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 4675 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4676 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 4680 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4681 | |
| 4682 | LocationSummary* locations = |
| 4683 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 4684 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4685 | bool is_volatile = field_info.IsVolatile(); |
| 4686 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4687 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 4688 | || (field_type == Primitive::kPrimByte); |
| 4689 | |
| 4690 | // The register allocator does not support multiple |
| 4691 | // inputs that die at entry with one in a specific register. |
| 4692 | if (is_byte_type) { |
| 4693 | // Ensure the value is in a byte register. |
| 4694 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4695 | } else if (Primitive::IsFloatingPointType(field_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4696 | if (is_volatile && field_type == Primitive::kPrimDouble) { |
| 4697 | // In order to satisfy the semantics of volatile, this must be a single instruction store. |
| 4698 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 4699 | } else { |
| 4700 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); |
| 4701 | } |
| 4702 | } else if (is_volatile && field_type == Primitive::kPrimLong) { |
| 4703 | // 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] | 4704 | locations->SetInAt(1, Location::RequiresRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4705 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4706 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 4707 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 4708 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 4709 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 4710 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 4711 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 4712 | locations->AddTemp(Location::RequiresFpuRegister()); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4713 | } else { |
| 4714 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4715 | |
| 4716 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
| 4717 | // Temporary registers for the write barrier. |
| 4718 | locations->AddTemp(Location::RequiresRegister()); // May be used for reference poisoning too. |
| 4719 | // Ensure the card is in a byte register. |
| 4720 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 4721 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4722 | } |
| 4723 | } |
| 4724 | |
| 4725 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4726 | const FieldInfo& field_info, |
| 4727 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4728 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 4729 | |
| 4730 | LocationSummary* locations = instruction->GetLocations(); |
| 4731 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 4732 | Location value = locations->InAt(1); |
| 4733 | bool is_volatile = field_info.IsVolatile(); |
| 4734 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4735 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4736 | bool needs_write_barrier = |
| 4737 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4738 | |
| 4739 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4740 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4741 | } |
| 4742 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4743 | bool maybe_record_implicit_null_check_done = false; |
| 4744 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4745 | switch (field_type) { |
| 4746 | case Primitive::kPrimBoolean: |
| 4747 | case Primitive::kPrimByte: { |
| 4748 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4749 | break; |
| 4750 | } |
| 4751 | |
| 4752 | case Primitive::kPrimShort: |
| 4753 | case Primitive::kPrimChar: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4754 | if (value.IsConstant()) { |
| 4755 | int16_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4756 | __ movw(Address(base, offset), Immediate(v)); |
| 4757 | } else { |
| 4758 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4759 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4760 | break; |
| 4761 | } |
| 4762 | |
| 4763 | case Primitive::kPrimInt: |
| 4764 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4765 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4766 | // Note that in the case where `value` is a null reference, |
| 4767 | // we do not enter this block, as the reference does not |
| 4768 | // need poisoning. |
| 4769 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4770 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4771 | __ movl(temp, value.AsRegister<Register>()); |
| 4772 | __ PoisonHeapReference(temp); |
| 4773 | __ movl(Address(base, offset), temp); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4774 | } else if (value.IsConstant()) { |
| 4775 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4776 | __ movl(Address(base, offset), Immediate(v)); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4777 | } else { |
Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 4778 | DCHECK(value.IsRegister()) << value; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4779 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4780 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4781 | break; |
| 4782 | } |
| 4783 | |
| 4784 | case Primitive::kPrimLong: { |
| 4785 | if (is_volatile) { |
| 4786 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4787 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4788 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4789 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4790 | __ punpckldq(temp1, temp2); |
| 4791 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4792 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4793 | } else if (value.IsConstant()) { |
| 4794 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4795 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4796 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4797 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4798 | } else { |
| 4799 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4800 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4801 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4802 | } |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4803 | maybe_record_implicit_null_check_done = true; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4804 | break; |
| 4805 | } |
| 4806 | |
| 4807 | case Primitive::kPrimFloat: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4808 | if (value.IsConstant()) { |
| 4809 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4810 | __ movl(Address(base, offset), Immediate(v)); |
| 4811 | } else { |
| 4812 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4813 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4814 | break; |
| 4815 | } |
| 4816 | |
| 4817 | case Primitive::kPrimDouble: { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4818 | if (value.IsConstant()) { |
| 4819 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); |
| 4820 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); |
| 4821 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4822 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); |
| 4823 | maybe_record_implicit_null_check_done = true; |
| 4824 | } else { |
| 4825 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4826 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4827 | break; |
| 4828 | } |
| 4829 | |
| 4830 | case Primitive::kPrimVoid: |
| 4831 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4832 | UNREACHABLE(); |
| 4833 | } |
| 4834 | |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 4835 | if (!maybe_record_implicit_null_check_done) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4836 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4837 | } |
| 4838 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4839 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4840 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4841 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4842 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4843 | } |
| 4844 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4845 | if (is_volatile) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4846 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4851 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4852 | } |
| 4853 | |
| 4854 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4855 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4856 | } |
| 4857 | |
| 4858 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4859 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4860 | } |
| 4861 | |
| 4862 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4863 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4867 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4868 | } |
| 4869 | |
| 4870 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4871 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4872 | } |
| 4873 | |
| 4874 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4875 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4876 | } |
| 4877 | |
| 4878 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4879 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4880 | } |
| 4881 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4882 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4883 | HUnresolvedInstanceFieldGet* instruction) { |
| 4884 | FieldAccessCallingConventionX86 calling_convention; |
| 4885 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4886 | instruction, instruction->GetFieldType(), calling_convention); |
| 4887 | } |
| 4888 | |
| 4889 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4890 | HUnresolvedInstanceFieldGet* instruction) { |
| 4891 | FieldAccessCallingConventionX86 calling_convention; |
| 4892 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4893 | instruction->GetFieldType(), |
| 4894 | instruction->GetFieldIndex(), |
| 4895 | instruction->GetDexPc(), |
| 4896 | calling_convention); |
| 4897 | } |
| 4898 | |
| 4899 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4900 | HUnresolvedInstanceFieldSet* instruction) { |
| 4901 | FieldAccessCallingConventionX86 calling_convention; |
| 4902 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4903 | instruction, instruction->GetFieldType(), calling_convention); |
| 4904 | } |
| 4905 | |
| 4906 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4907 | HUnresolvedInstanceFieldSet* instruction) { |
| 4908 | FieldAccessCallingConventionX86 calling_convention; |
| 4909 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4910 | instruction->GetFieldType(), |
| 4911 | instruction->GetFieldIndex(), |
| 4912 | instruction->GetDexPc(), |
| 4913 | calling_convention); |
| 4914 | } |
| 4915 | |
| 4916 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4917 | HUnresolvedStaticFieldGet* instruction) { |
| 4918 | FieldAccessCallingConventionX86 calling_convention; |
| 4919 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4920 | instruction, instruction->GetFieldType(), calling_convention); |
| 4921 | } |
| 4922 | |
| 4923 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4924 | HUnresolvedStaticFieldGet* instruction) { |
| 4925 | FieldAccessCallingConventionX86 calling_convention; |
| 4926 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4927 | instruction->GetFieldType(), |
| 4928 | instruction->GetFieldIndex(), |
| 4929 | instruction->GetDexPc(), |
| 4930 | calling_convention); |
| 4931 | } |
| 4932 | |
| 4933 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4934 | HUnresolvedStaticFieldSet* instruction) { |
| 4935 | FieldAccessCallingConventionX86 calling_convention; |
| 4936 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4937 | instruction, instruction->GetFieldType(), calling_convention); |
| 4938 | } |
| 4939 | |
| 4940 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4941 | HUnresolvedStaticFieldSet* instruction) { |
| 4942 | FieldAccessCallingConventionX86 calling_convention; |
| 4943 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4944 | instruction->GetFieldType(), |
| 4945 | instruction->GetFieldIndex(), |
| 4946 | instruction->GetDexPc(), |
| 4947 | calling_convention); |
| 4948 | } |
| 4949 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4950 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4951 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4952 | ? LocationSummary::kCallOnSlowPath |
| 4953 | : LocationSummary::kNoCall; |
| 4954 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4955 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4956 | ? Location::RequiresRegister() |
| 4957 | : Location::Any(); |
| 4958 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4959 | if (instruction->HasUses()) { |
| 4960 | locations->SetOut(Location::SameAsFirstInput()); |
| 4961 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4962 | } |
| 4963 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4964 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
| 4965 | if (CanMoveNullCheckToUser(instruction)) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4966 | return; |
| 4967 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4968 | LocationSummary* locations = instruction->GetLocations(); |
| 4969 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4970 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4971 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4972 | RecordPcInfo(instruction, instruction->GetDexPc()); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4973 | } |
| 4974 | |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4975 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4976 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4977 | AddSlowPath(slow_path); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4978 | |
| 4979 | LocationSummary* locations = instruction->GetLocations(); |
| 4980 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4981 | |
| 4982 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4983 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4984 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4985 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4986 | } else { |
| 4987 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4988 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4989 | __ jmp(slow_path->GetEntryLabel()); |
| 4990 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4991 | } |
| 4992 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4993 | } |
| 4994 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4995 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 4996 | codegen_->GenerateNullCheck(instruction); |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4997 | } |
| 4998 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4999 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5000 | bool object_array_get_with_read_barrier = |
| 5001 | kEmitCompilerReadBarrier && (instruction->GetType() == Primitive::kPrimNot); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5002 | LocationSummary* locations = |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5003 | new (GetGraph()->GetArena()) LocationSummary(instruction, |
| 5004 | object_array_get_with_read_barrier ? |
| 5005 | LocationSummary::kCallOnSlowPath : |
| 5006 | LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5007 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5008 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5009 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 5010 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 5011 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5012 | // The output overlaps in case of long: we don't want the low move |
| 5013 | // to overwrite the array's location. Likewise, in the case of an |
| 5014 | // object array get with read barriers enabled, we do not want the |
| 5015 | // move to overwrite the array's location, as we need it to emit |
| 5016 | // the read barrier. |
| 5017 | locations->SetOut( |
| 5018 | Location::RequiresRegister(), |
| 5019 | (instruction->GetType() == Primitive::kPrimLong || object_array_get_with_read_barrier) ? |
| 5020 | Location::kOutputOverlap : |
| 5021 | Location::kNoOutputOverlap); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5022 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5023 | // We need a temporary register for the read barrier marking slow |
| 5024 | // path in CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier. |
| 5025 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { |
| 5026 | locations->AddTemp(Location::RequiresRegister()); |
| 5027 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 5031 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5032 | Location obj_loc = locations->InAt(0); |
| 5033 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5034 | Location index = locations->InAt(1); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5035 | Location out_loc = locations->Out(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5036 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5037 | Primitive::Type type = instruction->GetType(); |
| 5038 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5039 | case Primitive::kPrimBoolean: { |
| 5040 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5041 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5042 | if (index.IsConstant()) { |
| 5043 | __ movzxb(out, Address(obj, |
| 5044 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5045 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5046 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5047 | } |
| 5048 | break; |
| 5049 | } |
| 5050 | |
| 5051 | case Primitive::kPrimByte: { |
| 5052 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5053 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5054 | if (index.IsConstant()) { |
| 5055 | __ movsxb(out, Address(obj, |
| 5056 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 5057 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5058 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5059 | } |
| 5060 | break; |
| 5061 | } |
| 5062 | |
| 5063 | case Primitive::kPrimShort: { |
| 5064 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5065 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5066 | if (index.IsConstant()) { |
| 5067 | __ movsxw(out, Address(obj, |
| 5068 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5069 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5070 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5071 | } |
| 5072 | break; |
| 5073 | } |
| 5074 | |
| 5075 | case Primitive::kPrimChar: { |
| 5076 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5077 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5078 | if (index.IsConstant()) { |
| 5079 | __ movzxw(out, Address(obj, |
| 5080 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 5081 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5082 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5083 | } |
| 5084 | break; |
| 5085 | } |
| 5086 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5087 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5088 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5089 | Register out = out_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5090 | if (index.IsConstant()) { |
| 5091 | __ movl(out, Address(obj, |
| 5092 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5093 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5094 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5095 | } |
| 5096 | break; |
| 5097 | } |
| 5098 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5099 | case Primitive::kPrimNot: { |
| 5100 | static_assert( |
| 5101 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), |
| 5102 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); |
| 5103 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5104 | // /* HeapReference<Object> */ out = |
| 5105 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 5106 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 5107 | Location temp = locations->GetTemp(0); |
| 5108 | // Note that a potential implicit null check is handled in this |
| 5109 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. |
| 5110 | codegen_->GenerateArrayLoadWithBakerReadBarrier( |
| 5111 | instruction, out_loc, obj, data_offset, index, temp, /* needs_null_check */ true); |
| 5112 | } else { |
| 5113 | Register out = out_loc.AsRegister<Register>(); |
| 5114 | if (index.IsConstant()) { |
| 5115 | uint32_t offset = |
| 5116 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; |
| 5117 | __ movl(out, Address(obj, offset)); |
| 5118 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5119 | // If read barriers are enabled, emit read barriers other than |
| 5120 | // Baker's using a slow path (and also unpoison the loaded |
| 5121 | // reference, if heap poisoning is enabled). |
| 5122 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); |
| 5123 | } else { |
| 5124 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5125 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5126 | // If read barriers are enabled, emit read barriers other than |
| 5127 | // Baker's using a slow path (and also unpoison the loaded |
| 5128 | // reference, if heap poisoning is enabled). |
| 5129 | codegen_->MaybeGenerateReadBarrierSlow( |
| 5130 | instruction, out_loc, out_loc, obj_loc, data_offset, index); |
| 5131 | } |
| 5132 | } |
| 5133 | break; |
| 5134 | } |
| 5135 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5136 | case Primitive::kPrimLong: { |
| 5137 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5138 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5139 | if (index.IsConstant()) { |
| 5140 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5141 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5142 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5143 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5144 | } else { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5145 | __ movl(out_loc.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5146 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5147 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5148 | __ movl(out_loc.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5149 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5150 | } |
| 5151 | break; |
| 5152 | } |
| 5153 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5154 | case Primitive::kPrimFloat: { |
| 5155 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5156 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5157 | if (index.IsConstant()) { |
| 5158 | __ movss(out, Address(obj, |
| 5159 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 5160 | } else { |
| 5161 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 5162 | } |
| 5163 | break; |
| 5164 | } |
| 5165 | |
| 5166 | case Primitive::kPrimDouble: { |
| 5167 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5168 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5169 | if (index.IsConstant()) { |
| 5170 | __ movsd(out, Address(obj, |
| 5171 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 5172 | } else { |
| 5173 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 5174 | } |
| 5175 | break; |
| 5176 | } |
| 5177 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5178 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5179 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5180 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5181 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5182 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5183 | if (type == Primitive::kPrimNot || type == Primitive::kPrimLong) { |
| 5184 | // Potential implicit null checks, in the case of reference or |
| 5185 | // long arrays, are handled in the previous switch statement. |
| 5186 | } else { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5187 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5188 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5192 | Primitive::Type value_type = instruction->GetComponentType(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5193 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5194 | bool needs_write_barrier = |
| 5195 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5196 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
| 5197 | bool object_array_set_with_read_barrier = |
| 5198 | kEmitCompilerReadBarrier && (value_type == Primitive::kPrimNot); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5199 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5200 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 5201 | instruction, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5202 | (may_need_runtime_call_for_type_check || object_array_set_with_read_barrier) ? |
| 5203 | LocationSummary::kCallOnSlowPath : |
| 5204 | LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5205 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5206 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 5207 | || (value_type == Primitive::kPrimByte); |
| 5208 | // We need the inputs to be different than the output in case of long operation. |
| 5209 | // In case of a byte operation, the register allocator does not support multiple |
| 5210 | // inputs that die at entry with one in a specific register. |
| 5211 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5212 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 5213 | if (is_byte_type) { |
| 5214 | // Ensure the value is in a byte register. |
| 5215 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 5216 | } else if (Primitive::IsFloatingPointType(value_type)) { |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5217 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5218 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5219 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 5220 | } |
| 5221 | if (needs_write_barrier) { |
| 5222 | // Temporary registers for the write barrier. |
| 5223 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 5224 | // Ensure the card is in a byte register. |
Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5225 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5226 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 5230 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5231 | Location array_loc = locations->InAt(0); |
| 5232 | Register array = array_loc.AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5233 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5234 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5235 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5236 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5237 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5238 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5239 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5240 | bool needs_write_barrier = |
| 5241 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5242 | |
| 5243 | switch (value_type) { |
| 5244 | case Primitive::kPrimBoolean: |
| 5245 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5246 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 5247 | Address address = index.IsConstant() |
| 5248 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 5249 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 5250 | if (value.IsRegister()) { |
| 5251 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5252 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5253 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5254 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5255 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5256 | break; |
| 5257 | } |
| 5258 | |
| 5259 | case Primitive::kPrimShort: |
| 5260 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5261 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 5262 | Address address = index.IsConstant() |
| 5263 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 5264 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 5265 | if (value.IsRegister()) { |
| 5266 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5267 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5268 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5269 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5270 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5271 | break; |
| 5272 | } |
| 5273 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5274 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5275 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5276 | Address address = index.IsConstant() |
| 5277 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5278 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5279 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5280 | if (!value.IsRegister()) { |
| 5281 | // Just setting null. |
| 5282 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 5283 | DCHECK(value.IsConstant()) << value; |
| 5284 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5285 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5286 | DCHECK(!needs_write_barrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5287 | DCHECK(!may_need_runtime_call_for_type_check); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5288 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5289 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5290 | |
| 5291 | DCHECK(needs_write_barrier); |
| 5292 | Register register_value = value.AsRegister<Register>(); |
| 5293 | NearLabel done, not_null, do_put; |
| 5294 | SlowPathCode* slow_path = nullptr; |
| 5295 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5296 | if (may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5297 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 5298 | codegen_->AddSlowPath(slow_path); |
| 5299 | if (instruction->GetValueCanBeNull()) { |
| 5300 | __ testl(register_value, register_value); |
| 5301 | __ j(kNotEqual, ¬_null); |
| 5302 | __ movl(address, Immediate(0)); |
| 5303 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5304 | __ jmp(&done); |
| 5305 | __ Bind(¬_null); |
| 5306 | } |
| 5307 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5308 | if (kEmitCompilerReadBarrier) { |
| 5309 | // When read barriers are enabled, the type checking |
| 5310 | // instrumentation requires two read barriers: |
| 5311 | // |
| 5312 | // __ movl(temp2, temp); |
| 5313 | // // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5314 | // __ movl(temp, Address(temp, component_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5315 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5316 | // instruction, temp_loc, temp_loc, temp2_loc, component_offset); |
| 5317 | // |
| 5318 | // // /* HeapReference<Class> */ temp2 = register_value->klass_ |
| 5319 | // __ movl(temp2, Address(register_value, class_offset)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5320 | // codegen_->GenerateReadBarrierSlow( |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5321 | // instruction, temp2_loc, temp2_loc, value, class_offset, temp_loc); |
| 5322 | // |
| 5323 | // __ cmpl(temp, temp2); |
| 5324 | // |
| 5325 | // However, the second read barrier may trash `temp`, as it |
| 5326 | // is a temporary register, and as such would not be saved |
| 5327 | // along with live registers before calling the runtime (nor |
| 5328 | // restored afterwards). So in this case, we bail out and |
| 5329 | // delegate the work to the array set slow path. |
| 5330 | // |
| 5331 | // TODO: Extend the register allocator to support a new |
| 5332 | // "(locally) live temp" location so as to avoid always |
| 5333 | // going into the slow path when read barriers are enabled. |
| 5334 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5335 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5336 | // /* HeapReference<Class> */ temp = array->klass_ |
| 5337 | __ movl(temp, Address(array, class_offset)); |
| 5338 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5339 | __ MaybeUnpoisonHeapReference(temp); |
| 5340 | |
| 5341 | // /* HeapReference<Class> */ temp = temp->component_type_ |
| 5342 | __ movl(temp, Address(temp, component_offset)); |
| 5343 | // If heap poisoning is enabled, no need to unpoison `temp` |
| 5344 | // nor the object reference in `register_value->klass`, as |
| 5345 | // we are comparing two poisoned references. |
| 5346 | __ cmpl(temp, Address(register_value, class_offset)); |
| 5347 | |
| 5348 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 5349 | __ j(kEqual, &do_put); |
| 5350 | // If heap poisoning is enabled, the `temp` reference has |
| 5351 | // not been unpoisoned yet; unpoison it now. |
| 5352 | __ MaybeUnpoisonHeapReference(temp); |
| 5353 | |
| 5354 | // /* HeapReference<Class> */ temp = temp->super_class_ |
| 5355 | __ movl(temp, Address(temp, super_offset)); |
| 5356 | // If heap poisoning is enabled, no need to unpoison |
| 5357 | // `temp`, as we are comparing against null below. |
| 5358 | __ testl(temp, temp); |
| 5359 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5360 | __ Bind(&do_put); |
| 5361 | } else { |
| 5362 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5363 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5364 | } |
| 5365 | } |
| 5366 | |
| 5367 | if (kPoisonHeapReferences) { |
| 5368 | __ movl(temp, register_value); |
| 5369 | __ PoisonHeapReference(temp); |
| 5370 | __ movl(address, temp); |
| 5371 | } else { |
| 5372 | __ movl(address, register_value); |
| 5373 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5374 | if (!may_need_runtime_call_for_type_check) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5375 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5376 | } |
| 5377 | |
| 5378 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 5379 | codegen_->MarkGCCard( |
| 5380 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 5381 | __ Bind(&done); |
| 5382 | |
| 5383 | if (slow_path != nullptr) { |
| 5384 | __ Bind(slow_path->GetExitLabel()); |
| 5385 | } |
| 5386 | |
| 5387 | break; |
| 5388 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5389 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5390 | case Primitive::kPrimInt: { |
| 5391 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 5392 | Address address = index.IsConstant() |
| 5393 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5394 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 5395 | if (value.IsRegister()) { |
| 5396 | __ movl(address, value.AsRegister<Register>()); |
| 5397 | } else { |
| 5398 | DCHECK(value.IsConstant()) << value; |
| 5399 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 5400 | __ movl(address, Immediate(v)); |
| 5401 | } |
| 5402 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5403 | break; |
| 5404 | } |
| 5405 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5406 | case Primitive::kPrimLong: { |
| 5407 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5408 | if (index.IsConstant()) { |
| 5409 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5410 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5411 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5412 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5413 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5414 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5415 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5416 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5417 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5418 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5419 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5420 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5421 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5422 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5423 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5424 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5425 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5426 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5427 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5428 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 5429 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5430 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5431 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5432 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5433 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5434 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5435 | Immediate(High32Bits(val))); |
| 5436 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5437 | } |
| 5438 | break; |
| 5439 | } |
| 5440 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5441 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5442 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 5443 | Address address = index.IsConstant() |
| 5444 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 5445 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5446 | if (value.IsFpuRegister()) { |
| 5447 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
| 5448 | } else { |
| 5449 | DCHECK(value.IsConstant()); |
| 5450 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); |
| 5451 | __ movl(address, Immediate(v)); |
| 5452 | } |
| 5453 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5454 | break; |
| 5455 | } |
| 5456 | |
| 5457 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5458 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 5459 | Address address = index.IsConstant() |
| 5460 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 5461 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5462 | if (value.IsFpuRegister()) { |
| 5463 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
| 5464 | } else { |
| 5465 | DCHECK(value.IsConstant()); |
| 5466 | Address address_hi = index.IsConstant() ? |
| 5467 | Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + |
| 5468 | offset + kX86WordSize) : |
| 5469 | Address(array, index.AsRegister<Register>(), TIMES_8, offset + kX86WordSize); |
| 5470 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); |
| 5471 | __ movl(address, Immediate(Low32Bits(v))); |
| 5472 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 5473 | __ movl(address_hi, Immediate(High32Bits(v))); |
| 5474 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5475 | break; |
| 5476 | } |
| 5477 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5478 | case Primitive::kPrimVoid: |
| 5479 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5480 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5481 | } |
| 5482 | } |
| 5483 | |
| 5484 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 5485 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5486 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5487 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 5491 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5492 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5493 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 5494 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5495 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5496 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5500 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 5501 | ? LocationSummary::kCallOnSlowPath |
| 5502 | : LocationSummary::kNoCall; |
| 5503 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5504 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5505 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5506 | if (instruction->HasUses()) { |
| 5507 | locations->SetOut(Location::SameAsFirstInput()); |
| 5508 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 5512 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5513 | Location index_loc = locations->InAt(0); |
| 5514 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5515 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 5516 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5517 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5518 | if (length_loc.IsConstant()) { |
| 5519 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 5520 | if (index_loc.IsConstant()) { |
| 5521 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 5522 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5523 | if (index < 0 || index >= length) { |
| 5524 | codegen_->AddSlowPath(slow_path); |
| 5525 | __ jmp(slow_path->GetEntryLabel()); |
| 5526 | } else { |
| 5527 | // Some optimization after BCE may have generated this, and we should not |
| 5528 | // generate a bounds check if it is a valid range. |
| 5529 | } |
| 5530 | return; |
| 5531 | } |
| 5532 | |
| 5533 | // We have to reverse the jump condition because the length is the constant. |
| 5534 | Register index_reg = index_loc.AsRegister<Register>(); |
| 5535 | __ cmpl(index_reg, Immediate(length)); |
| 5536 | codegen_->AddSlowPath(slow_path); |
| 5537 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5538 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 5539 | Register length = length_loc.AsRegister<Register>(); |
| 5540 | if (index_loc.IsConstant()) { |
| 5541 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 5542 | __ cmpl(length, Immediate(value)); |
| 5543 | } else { |
| 5544 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 5545 | } |
| 5546 | codegen_->AddSlowPath(slow_path); |
| 5547 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 5548 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5549 | } |
| 5550 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5551 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5552 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5556 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 5557 | } |
| 5558 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5559 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 5560 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 5561 | } |
| 5562 | |
| 5563 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5564 | HBasicBlock* block = instruction->GetBlock(); |
| 5565 | if (block->GetLoopInformation() != nullptr) { |
| 5566 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 5567 | // The back edge will generate the suspend check. |
| 5568 | return; |
| 5569 | } |
| 5570 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 5571 | // The goto will generate the suspend check. |
| 5572 | return; |
| 5573 | } |
| 5574 | GenerateSuspendCheck(instruction, nullptr); |
| 5575 | } |
| 5576 | |
| 5577 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 5578 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5579 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5580 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 5581 | if (slow_path == nullptr) { |
| 5582 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 5583 | instruction->SetSlowPath(slow_path); |
| 5584 | codegen_->AddSlowPath(slow_path); |
| 5585 | if (successor != nullptr) { |
| 5586 | DCHECK(successor->IsLoopHeader()); |
| 5587 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 5588 | } |
| 5589 | } else { |
| 5590 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 5591 | } |
| 5592 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5593 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), |
| 5594 | Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 5595 | if (successor == nullptr) { |
| 5596 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5597 | __ Bind(slow_path->GetReturnLabel()); |
| 5598 | } else { |
| 5599 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 5600 | __ jmp(slow_path->GetEntryLabel()); |
| 5601 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5602 | } |
| 5603 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5604 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 5605 | return codegen_->GetAssembler(); |
| 5606 | } |
| 5607 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5608 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5609 | ScratchRegisterScope ensure_scratch( |
| 5610 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5611 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5612 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5613 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5614 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5615 | } |
| 5616 | |
| 5617 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5618 | ScratchRegisterScope ensure_scratch( |
| 5619 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5620 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5621 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5622 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 5623 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 5624 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 5625 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5629 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5630 | Location source = move->GetSource(); |
| 5631 | Location destination = move->GetDestination(); |
| 5632 | |
| 5633 | if (source.IsRegister()) { |
| 5634 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5635 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5636 | } else if (destination.IsFpuRegister()) { |
| 5637 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5638 | } else { |
| 5639 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5640 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5641 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5642 | } else if (source.IsRegisterPair()) { |
| 5643 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 5644 | // Create stack space for 2 elements. |
| 5645 | __ subl(ESP, Immediate(2 * elem_size)); |
| 5646 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 5647 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 5648 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 5649 | // And remove the temporary stack space we allocated. |
| 5650 | __ addl(ESP, Immediate(2 * elem_size)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5651 | } else if (source.IsFpuRegister()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5652 | if (destination.IsRegister()) { |
| 5653 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
| 5654 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5655 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5656 | } else if (destination.IsRegisterPair()) { |
| 5657 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 5658 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 5659 | __ psrlq(src_reg, Immediate(32)); |
| 5660 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5661 | } else if (destination.IsStackSlot()) { |
| 5662 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5663 | } else { |
| 5664 | DCHECK(destination.IsDoubleStackSlot()); |
| 5665 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 5666 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5667 | } else if (source.IsStackSlot()) { |
| 5668 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5669 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5670 | } else if (destination.IsFpuRegister()) { |
| 5671 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5672 | } else { |
| 5673 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5674 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 5675 | } |
| 5676 | } else if (source.IsDoubleStackSlot()) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 5677 | if (destination.IsRegisterPair()) { |
| 5678 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 5679 | __ movl(destination.AsRegisterPairHigh<Register>(), |
| 5680 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 5681 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5682 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 5683 | } else { |
| 5684 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5685 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5686 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5687 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5688 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 5689 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5690 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5691 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5692 | if (value == 0) { |
| 5693 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5694 | } else { |
| 5695 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 5696 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5697 | } else { |
| 5698 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 5699 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5700 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5701 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5702 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5703 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5704 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5705 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5706 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5707 | if (value == 0) { |
| 5708 | // Easy handling of 0.0. |
| 5709 | __ xorps(dest, dest); |
| 5710 | } else { |
| 5711 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5712 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5713 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5714 | __ movl(temp, Immediate(value)); |
| 5715 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5716 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5717 | } else { |
| 5718 | DCHECK(destination.IsStackSlot()) << destination; |
| 5719 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 5720 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5721 | } else if (constant->IsLongConstant()) { |
| 5722 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 5723 | int32_t low_value = Low32Bits(value); |
| 5724 | int32_t high_value = High32Bits(value); |
| 5725 | Immediate low(low_value); |
| 5726 | Immediate high(high_value); |
| 5727 | if (destination.IsDoubleStackSlot()) { |
| 5728 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5729 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5730 | } else { |
| 5731 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 5732 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 5733 | } |
| 5734 | } else { |
| 5735 | DCHECK(constant->IsDoubleConstant()); |
| 5736 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 5737 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5738 | int32_t low_value = Low32Bits(value); |
| 5739 | int32_t high_value = High32Bits(value); |
| 5740 | Immediate low(low_value); |
| 5741 | Immediate high(high_value); |
| 5742 | if (destination.IsFpuRegister()) { |
| 5743 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 5744 | if (value == 0) { |
| 5745 | // Easy handling of 0.0. |
| 5746 | __ xorpd(dest, dest); |
| 5747 | } else { |
| 5748 | __ pushl(high); |
| 5749 | __ pushl(low); |
| 5750 | __ movsd(dest, Address(ESP, 0)); |
| 5751 | __ addl(ESP, Immediate(8)); |
| 5752 | } |
| 5753 | } else { |
| 5754 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 5755 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 5756 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 5757 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 5758 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5759 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5760 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5761 | } |
| 5762 | } |
| 5763 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 5764 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5765 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 5766 | ScratchRegisterScope ensure_scratch( |
| 5767 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 5768 | |
| 5769 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5770 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 5771 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 5772 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5773 | } |
| 5774 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5775 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5776 | ScratchRegisterScope ensure_scratch( |
| 5777 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 5778 | |
| 5779 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 5780 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 5781 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 5782 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 5783 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5784 | } |
| 5785 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5786 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5787 | ScratchRegisterScope ensure_scratch1( |
| 5788 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5789 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5790 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 5791 | ScratchRegisterScope ensure_scratch2( |
| 5792 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 5793 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 5794 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 5795 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 5796 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 5797 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 5798 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 5799 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5803 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5804 | Location source = move->GetSource(); |
| 5805 | Location destination = move->GetDestination(); |
| 5806 | |
| 5807 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 5808 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 5809 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5810 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 5811 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 5812 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5813 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5814 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5815 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5816 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5817 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 5818 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5819 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 5820 | // Use XOR Swap algorithm to avoid a temporary. |
| 5821 | DCHECK_NE(source.reg(), destination.reg()); |
| 5822 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5823 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 5824 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 5825 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 5826 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 5827 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 5828 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5829 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 5830 | // Take advantage of the 16 bytes in the XMM register. |
| 5831 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 5832 | Address stack(ESP, destination.GetStackIndex()); |
| 5833 | // Load the double into the high doubleword. |
| 5834 | __ movhpd(reg, stack); |
| 5835 | |
| 5836 | // Store the low double into the destination. |
| 5837 | __ movsd(stack, reg); |
| 5838 | |
| 5839 | // Move the high double to the low double. |
| 5840 | __ psrldq(reg, Immediate(8)); |
| 5841 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 5842 | // Take advantage of the 16 bytes in the XMM register. |
| 5843 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 5844 | Address stack(ESP, source.GetStackIndex()); |
| 5845 | // Load the double into the high doubleword. |
| 5846 | __ movhpd(reg, stack); |
| 5847 | |
| 5848 | // Store the low double into the destination. |
| 5849 | __ movsd(stack, reg); |
| 5850 | |
| 5851 | // Move the high double to the low double. |
| 5852 | __ psrldq(reg, Immediate(8)); |
| 5853 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 5854 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 5855 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5856 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5857 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 5858 | } |
| 5859 | } |
| 5860 | |
| 5861 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 5862 | __ pushl(static_cast<Register>(reg)); |
| 5863 | } |
| 5864 | |
| 5865 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 5866 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5867 | } |
| 5868 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5869 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5870 | InvokeRuntimeCallingConvention calling_convention; |
| 5871 | CodeGenerator::CreateLoadClassLocationSummary( |
| 5872 | cls, |
| 5873 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5874 | Location::RegisterLocation(EAX), |
| 5875 | /* code_generator_supports_read_barrier */ true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5876 | } |
| 5877 | |
| 5878 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5879 | LocationSummary* locations = cls->GetLocations(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5880 | if (cls->NeedsAccessCheck()) { |
| 5881 | codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex()); |
| 5882 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInitializeTypeAndVerifyAccess), |
| 5883 | cls, |
| 5884 | cls->GetDexPc(), |
| 5885 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 5886 | CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5887 | return; |
| 5888 | } |
| 5889 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5890 | Location out_loc = locations->Out(); |
| 5891 | Register out = out_loc.AsRegister<Register>(); |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5892 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5893 | |
Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 5894 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5895 | DCHECK(!cls->CanCallRuntime()); |
| 5896 | DCHECK(!cls->MustGenerateClinitCheck()); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5897 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 5898 | GenerateGcRootFieldLoad( |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5899 | cls, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5900 | } else { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5901 | // /* GcRoot<mirror::Class>[] */ out = |
| 5902 | // current_method.ptr_sized_fields_->dex_cache_resolved_types_ |
| 5903 | __ movl(out, Address(current_method, |
| 5904 | ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5905 | // /* GcRoot<mirror::Class> */ out = out[type_index] |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5906 | GenerateGcRootFieldLoad( |
| 5907 | cls, out_loc, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5908 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5909 | if (!cls->IsInDexCache() || cls->MustGenerateClinitCheck()) { |
| 5910 | DCHECK(cls->CanCallRuntime()); |
| 5911 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
| 5912 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5913 | codegen_->AddSlowPath(slow_path); |
| 5914 | |
| 5915 | if (!cls->IsInDexCache()) { |
| 5916 | __ testl(out, out); |
| 5917 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5918 | } |
| 5919 | |
| 5920 | if (cls->MustGenerateClinitCheck()) { |
| 5921 | GenerateClassInitializationCheck(slow_path, out); |
| 5922 | } else { |
| 5923 | __ Bind(slow_path->GetExitLabel()); |
| 5924 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5925 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5926 | } |
| 5927 | } |
| 5928 | |
| 5929 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5930 | LocationSummary* locations = |
| 5931 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5932 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5933 | if (check->HasUses()) { |
| 5934 | locations->SetOut(Location::SameAsFirstInput()); |
| 5935 | } |
| 5936 | } |
| 5937 | |
| 5938 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5939 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5940 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5941 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5942 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5943 | GenerateClassInitializationCheck(slow_path, |
| 5944 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5945 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5946 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5947 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5948 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5949 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5950 | Immediate(mirror::Class::kStatusInitialized)); |
| 5951 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5952 | __ Bind(slow_path->GetExitLabel()); |
| 5953 | // No need for memory fence, thanks to the X86 memory model. |
| 5954 | } |
| 5955 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5956 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( |
| 5957 | HLoadString::LoadKind desired_string_load_kind) { |
| 5958 | if (kEmitCompilerReadBarrier) { |
| 5959 | switch (desired_string_load_kind) { |
| 5960 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5961 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5962 | case HLoadString::LoadKind::kBootImageAddress: |
| 5963 | // TODO: Implement for read barrier. |
| 5964 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5965 | default: |
| 5966 | break; |
| 5967 | } |
| 5968 | } |
| 5969 | switch (desired_string_load_kind) { |
| 5970 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: |
| 5971 | DCHECK(!GetCompilerOptions().GetCompilePic()); |
| 5972 | break; |
| 5973 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: |
| 5974 | DCHECK(GetCompilerOptions().GetCompilePic()); |
| 5975 | FALLTHROUGH_INTENDED; |
| 5976 | case HLoadString::LoadKind::kDexCachePcRelative: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5977 | DCHECK(!Runtime::Current()->UseJitCompilation()); // Note: boot image is also non-JIT. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5978 | // We disable pc-relative load when there is an irreducible loop, as the optimization |
| 5979 | // is incompatible with it. |
| 5980 | // TODO: Create as many X86ComputeBaseMethodAddress instructions as needed for methods |
| 5981 | // with irreducible loops. |
| 5982 | if (GetGraph()->HasIrreducibleLoops()) { |
| 5983 | return HLoadString::LoadKind::kDexCacheViaMethod; |
| 5984 | } |
| 5985 | break; |
| 5986 | case HLoadString::LoadKind::kBootImageAddress: |
| 5987 | break; |
| 5988 | case HLoadString::LoadKind::kDexCacheAddress: |
Calin Juravle | ffc8707 | 2016-04-20 14:22:09 +0100 | [diff] [blame] | 5989 | DCHECK(Runtime::Current()->UseJitCompilation()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5990 | break; |
| 5991 | case HLoadString::LoadKind::kDexCacheViaMethod: |
| 5992 | break; |
| 5993 | } |
| 5994 | return desired_string_load_kind; |
| 5995 | } |
| 5996 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5997 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5998 | LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier) |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5999 | ? LocationSummary::kCallOnSlowPath |
| 6000 | : LocationSummary::kNoCall; |
| 6001 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6002 | HLoadString::LoadKind load_kind = load->GetLoadKind(); |
| 6003 | if (load_kind == HLoadString::LoadKind::kDexCacheViaMethod || |
| 6004 | load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || |
| 6005 | load_kind == HLoadString::LoadKind::kDexCachePcRelative) { |
| 6006 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6007 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6008 | locations->SetOut(Location::RequiresRegister()); |
| 6009 | } |
| 6010 | |
| 6011 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6012 | LocationSummary* locations = load->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6013 | Location out_loc = locations->Out(); |
| 6014 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6015 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6016 | switch (load->GetLoadKind()) { |
| 6017 | case HLoadString::LoadKind::kBootImageLinkTimeAddress: { |
| 6018 | DCHECK(!kEmitCompilerReadBarrier); |
| 6019 | __ movl(out, Immediate(/* placeholder */ 0)); |
| 6020 | codegen_->RecordStringPatch(load); |
| 6021 | return; // No dex cache slow path. |
| 6022 | } |
| 6023 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { |
| 6024 | DCHECK(!kEmitCompilerReadBarrier); |
| 6025 | Register method_address = locations->InAt(0).AsRegister<Register>(); |
| 6026 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); |
| 6027 | codegen_->RecordStringPatch(load); |
| 6028 | return; // No dex cache slow path. |
| 6029 | } |
| 6030 | case HLoadString::LoadKind::kBootImageAddress: { |
| 6031 | DCHECK(!kEmitCompilerReadBarrier); |
| 6032 | DCHECK_NE(load->GetAddress(), 0u); |
| 6033 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6034 | __ movl(out, Immediate(address)); |
| 6035 | codegen_->RecordSimplePatch(); |
| 6036 | return; // No dex cache slow path. |
| 6037 | } |
| 6038 | case HLoadString::LoadKind::kDexCacheAddress: { |
| 6039 | DCHECK_NE(load->GetAddress(), 0u); |
| 6040 | uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress()); |
| 6041 | GenerateGcRootFieldLoad(load, out_loc, Address::Absolute(address)); |
| 6042 | break; |
| 6043 | } |
| 6044 | case HLoadString::LoadKind::kDexCachePcRelative: { |
| 6045 | Register base_reg = locations->InAt(0).AsRegister<Register>(); |
| 6046 | uint32_t offset = load->GetDexCacheElementOffset(); |
| 6047 | Label* fixup_label = codegen_->NewPcRelativeDexCacheArrayPatch(load->GetDexFile(), offset); |
| 6048 | GenerateGcRootFieldLoad( |
| 6049 | load, out_loc, Address(base_reg, CodeGeneratorX86::kDummy32BitOffset), fixup_label); |
| 6050 | break; |
| 6051 | } |
| 6052 | case HLoadString::LoadKind::kDexCacheViaMethod: { |
| 6053 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
| 6054 | |
| 6055 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ |
| 6056 | GenerateGcRootFieldLoad( |
| 6057 | load, out_loc, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 6058 | |
| 6059 | // /* GcRoot<mirror::String>[] */ out = out->dex_cache_strings_ |
| 6060 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
| 6061 | // /* GcRoot<mirror::String> */ out = out[string_index] |
| 6062 | GenerateGcRootFieldLoad( |
| 6063 | load, out_loc, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
| 6064 | break; |
| 6065 | } |
| 6066 | default: |
| 6067 | LOG(FATAL) << "Unexpected load kind: " << load->GetLoadKind(); |
| 6068 | UNREACHABLE(); |
| 6069 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6070 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6071 | if (!load->IsInDexCache()) { |
| 6072 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
| 6073 | codegen_->AddSlowPath(slow_path); |
| 6074 | __ testl(out, out); |
| 6075 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6076 | __ Bind(slow_path->GetExitLabel()); |
| 6077 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6078 | } |
| 6079 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6080 | static Address GetExceptionTlsAddress() { |
| 6081 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 6082 | } |
| 6083 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6084 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 6085 | LocationSummary* locations = |
| 6086 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 6087 | locations->SetOut(Location::RequiresRegister()); |
| 6088 | } |
| 6089 | |
| 6090 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6091 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 6092 | } |
| 6093 | |
| 6094 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 6095 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 6096 | } |
| 6097 | |
| 6098 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 6099 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6100 | } |
| 6101 | |
| 6102 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 6103 | LocationSummary* locations = |
| 6104 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6105 | InvokeRuntimeCallingConvention calling_convention; |
| 6106 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6107 | } |
| 6108 | |
| 6109 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6110 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 6111 | instruction, |
| 6112 | instruction->GetDexPc(), |
| 6113 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6114 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6115 | } |
| 6116 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6117 | static bool TypeCheckNeedsATemporary(TypeCheckKind type_check_kind) { |
| 6118 | return kEmitCompilerReadBarrier && |
| 6119 | (kUseBakerReadBarrier || |
| 6120 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6121 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6122 | type_check_kind == TypeCheckKind::kArrayObjectCheck); |
| 6123 | } |
| 6124 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6125 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6126 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6127 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6128 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6129 | case TypeCheckKind::kExactCheck: |
| 6130 | case TypeCheckKind::kAbstractClassCheck: |
| 6131 | case TypeCheckKind::kClassHierarchyCheck: |
| 6132 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6133 | call_kind = |
| 6134 | kEmitCompilerReadBarrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6135 | break; |
| 6136 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6137 | case TypeCheckKind::kUnresolvedCheck: |
| 6138 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6139 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6140 | break; |
| 6141 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6142 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6143 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6144 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6145 | locations->SetInAt(1, Location::Any()); |
| 6146 | // Note that TypeCheckSlowPathX86 uses this "out" register too. |
| 6147 | locations->SetOut(Location::RequiresRegister()); |
| 6148 | // When read barriers are enabled, we need a temporary register for |
| 6149 | // some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6150 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6151 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6152 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6153 | } |
| 6154 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6155 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6156 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6157 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6158 | Location obj_loc = locations->InAt(0); |
| 6159 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6160 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6161 | Location out_loc = locations->Out(); |
| 6162 | Register out = out_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6163 | Location maybe_temp_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6164 | locations->GetTemp(0) : |
| 6165 | Location::NoLocation(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6166 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6167 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6168 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6169 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6170 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6171 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6172 | |
| 6173 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6174 | // Avoid null check if we know obj is not null. |
| 6175 | if (instruction->MustDoNullCheck()) { |
| 6176 | __ testl(obj, obj); |
| 6177 | __ j(kEqual, &zero); |
| 6178 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6179 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6180 | // /* HeapReference<Class> */ out = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6181 | GenerateReferenceLoadTwoRegisters(instruction, out_loc, obj_loc, class_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6182 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6183 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6184 | case TypeCheckKind::kExactCheck: { |
| 6185 | if (cls.IsRegister()) { |
| 6186 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6187 | } else { |
| 6188 | DCHECK(cls.IsStackSlot()) << cls; |
| 6189 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6190 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6191 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6192 | // Classes must be equal for the instanceof to succeed. |
| 6193 | __ j(kNotEqual, &zero); |
| 6194 | __ movl(out, Immediate(1)); |
| 6195 | __ jmp(&done); |
| 6196 | break; |
| 6197 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6198 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6199 | case TypeCheckKind::kAbstractClassCheck: { |
| 6200 | // If the class is abstract, we eagerly fetch the super class of the |
| 6201 | // object to avoid doing a comparison we know will fail. |
| 6202 | NearLabel loop; |
| 6203 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6204 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6205 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6206 | __ testl(out, out); |
| 6207 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6208 | __ j(kEqual, &done); |
| 6209 | if (cls.IsRegister()) { |
| 6210 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6211 | } else { |
| 6212 | DCHECK(cls.IsStackSlot()) << cls; |
| 6213 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6214 | } |
| 6215 | __ j(kNotEqual, &loop); |
| 6216 | __ movl(out, Immediate(1)); |
| 6217 | if (zero.IsLinked()) { |
| 6218 | __ jmp(&done); |
| 6219 | } |
| 6220 | break; |
| 6221 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6222 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6223 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6224 | // Walk over the class hierarchy to find a match. |
| 6225 | NearLabel loop, success; |
| 6226 | __ Bind(&loop); |
| 6227 | if (cls.IsRegister()) { |
| 6228 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6229 | } else { |
| 6230 | DCHECK(cls.IsStackSlot()) << cls; |
| 6231 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6232 | } |
| 6233 | __ j(kEqual, &success); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6234 | // /* HeapReference<Class> */ out = out->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6235 | GenerateReferenceLoadOneRegister(instruction, out_loc, super_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6236 | __ testl(out, out); |
| 6237 | __ j(kNotEqual, &loop); |
| 6238 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6239 | __ jmp(&done); |
| 6240 | __ Bind(&success); |
| 6241 | __ movl(out, Immediate(1)); |
| 6242 | if (zero.IsLinked()) { |
| 6243 | __ jmp(&done); |
| 6244 | } |
| 6245 | break; |
| 6246 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6247 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6248 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6249 | // Do an exact check. |
| 6250 | NearLabel exact_check; |
| 6251 | if (cls.IsRegister()) { |
| 6252 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6253 | } else { |
| 6254 | DCHECK(cls.IsStackSlot()) << cls; |
| 6255 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6256 | } |
| 6257 | __ j(kEqual, &exact_check); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6258 | // 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] | 6259 | // /* HeapReference<Class> */ out = out->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6260 | GenerateReferenceLoadOneRegister(instruction, out_loc, component_offset, maybe_temp_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6261 | __ testl(out, out); |
| 6262 | // If `out` is null, we use it for the result, and jump to `done`. |
| 6263 | __ j(kEqual, &done); |
| 6264 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 6265 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6266 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6267 | __ movl(out, Immediate(1)); |
| 6268 | __ jmp(&done); |
| 6269 | break; |
| 6270 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6271 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6272 | case TypeCheckKind::kArrayCheck: { |
| 6273 | if (cls.IsRegister()) { |
| 6274 | __ cmpl(out, cls.AsRegister<Register>()); |
| 6275 | } else { |
| 6276 | DCHECK(cls.IsStackSlot()) << cls; |
| 6277 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 6278 | } |
| 6279 | DCHECK(locations->OnlyCallsOnSlowPath()); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6280 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6281 | /* is_fatal */ false); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6282 | codegen_->AddSlowPath(slow_path); |
| 6283 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6284 | __ movl(out, Immediate(1)); |
| 6285 | if (zero.IsLinked()) { |
| 6286 | __ jmp(&done); |
| 6287 | } |
| 6288 | break; |
| 6289 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6290 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6291 | case TypeCheckKind::kUnresolvedCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6292 | case TypeCheckKind::kInterfaceCheck: { |
| 6293 | // Note that we indeed only call on slow path, but we always go |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6294 | // into the slow path for the unresolved and interface check |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6295 | // cases. |
| 6296 | // |
| 6297 | // We cannot directly call the InstanceofNonTrivial runtime |
| 6298 | // entry point without resorting to a type checking slow path |
| 6299 | // here (i.e. by calling InvokeRuntime directly), as it would |
| 6300 | // require to assign fixed registers for the inputs of this |
| 6301 | // HInstanceOf instruction (following the runtime calling |
| 6302 | // convention), which might be cluttered by the potential first |
| 6303 | // read barrier emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6304 | // |
| 6305 | // TODO: Introduce a new runtime entry point taking the object |
| 6306 | // to test (instead of its class) as argument, and let it deal |
| 6307 | // with the read barrier issues. This will let us refactor this |
| 6308 | // case of the `switch` code as it was previously (with a direct |
| 6309 | // call to the runtime not using a type checking slow path). |
| 6310 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6311 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 6312 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6313 | /* is_fatal */ false); |
| 6314 | codegen_->AddSlowPath(slow_path); |
| 6315 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6316 | if (zero.IsLinked()) { |
| 6317 | __ jmp(&done); |
| 6318 | } |
| 6319 | break; |
| 6320 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6321 | } |
| 6322 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6323 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6324 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6325 | __ xorl(out, out); |
| 6326 | } |
| 6327 | |
| 6328 | if (done.IsLinked()) { |
| 6329 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6330 | } |
| 6331 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6332 | if (slow_path != nullptr) { |
| 6333 | __ Bind(slow_path->GetExitLabel()); |
| 6334 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6335 | } |
| 6336 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6337 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6338 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 6339 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6340 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
| 6341 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6342 | case TypeCheckKind::kExactCheck: |
| 6343 | case TypeCheckKind::kAbstractClassCheck: |
| 6344 | case TypeCheckKind::kClassHierarchyCheck: |
| 6345 | case TypeCheckKind::kArrayObjectCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6346 | call_kind = (throws_into_catch || kEmitCompilerReadBarrier) ? |
| 6347 | LocationSummary::kCallOnSlowPath : |
| 6348 | LocationSummary::kNoCall; // In fact, call on a fatal (non-returning) slow path. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6349 | break; |
| 6350 | case TypeCheckKind::kArrayCheck: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6351 | case TypeCheckKind::kUnresolvedCheck: |
| 6352 | case TypeCheckKind::kInterfaceCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6353 | call_kind = LocationSummary::kCallOnSlowPath; |
| 6354 | break; |
| 6355 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6356 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 6357 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6358 | locations->SetInAt(1, Location::Any()); |
| 6359 | // Note that TypeCheckSlowPathX86 uses this "temp" register too. |
| 6360 | locations->AddTemp(Location::RequiresRegister()); |
| 6361 | // When read barriers are enabled, we need an additional temporary |
| 6362 | // register for some cases. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6363 | if (TypeCheckNeedsATemporary(type_check_kind)) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6364 | locations->AddTemp(Location::RequiresRegister()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6365 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6366 | } |
| 6367 | |
| 6368 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6369 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6370 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6371 | Location obj_loc = locations->InAt(0); |
| 6372 | Register obj = obj_loc.AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6373 | Location cls = locations->InAt(1); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6374 | Location temp_loc = locations->GetTemp(0); |
| 6375 | Register temp = temp_loc.AsRegister<Register>(); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6376 | Location maybe_temp2_loc = TypeCheckNeedsATemporary(type_check_kind) ? |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6377 | locations->GetTemp(1) : |
| 6378 | Location::NoLocation(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6379 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 6380 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 6381 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 6382 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6383 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6384 | bool is_type_check_slow_path_fatal = |
| 6385 | (type_check_kind == TypeCheckKind::kExactCheck || |
| 6386 | type_check_kind == TypeCheckKind::kAbstractClassCheck || |
| 6387 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || |
| 6388 | type_check_kind == TypeCheckKind::kArrayObjectCheck) && |
| 6389 | !instruction->CanThrowIntoCatchBlock(); |
| 6390 | SlowPathCode* type_check_slow_path = |
| 6391 | new (GetGraph()->GetArena()) TypeCheckSlowPathX86(instruction, |
| 6392 | is_type_check_slow_path_fatal); |
| 6393 | codegen_->AddSlowPath(type_check_slow_path); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6394 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6395 | NearLabel done; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6396 | // Avoid null check if we know obj is not null. |
| 6397 | if (instruction->MustDoNullCheck()) { |
| 6398 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6399 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6400 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6401 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6402 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6403 | GenerateReferenceLoadTwoRegisters(instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6404 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6405 | switch (type_check_kind) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6406 | case TypeCheckKind::kExactCheck: |
| 6407 | case TypeCheckKind::kArrayCheck: { |
| 6408 | if (cls.IsRegister()) { |
| 6409 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6410 | } else { |
| 6411 | DCHECK(cls.IsStackSlot()) << cls; |
| 6412 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6413 | } |
| 6414 | // Jump to slow path for throwing the exception or doing a |
| 6415 | // more involved array check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6416 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6417 | break; |
| 6418 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6419 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6420 | case TypeCheckKind::kAbstractClassCheck: { |
| 6421 | // If the class is abstract, we eagerly fetch the super class of the |
| 6422 | // object to avoid doing a comparison we know will fail. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6423 | NearLabel loop, compare_classes; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6424 | __ Bind(&loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6425 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6426 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6427 | |
| 6428 | // If the class reference currently in `temp` is not null, jump |
| 6429 | // to the `compare_classes` label to compare it with the checked |
| 6430 | // class. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6431 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6432 | __ j(kNotEqual, &compare_classes); |
| 6433 | // Otherwise, jump to the slow path to throw the exception. |
| 6434 | // |
| 6435 | // But before, move back the object's class into `temp` before |
| 6436 | // going into the slow path, as it has been overwritten in the |
| 6437 | // meantime. |
| 6438 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6439 | GenerateReferenceLoadTwoRegisters( |
| 6440 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6441 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6442 | |
| 6443 | __ Bind(&compare_classes); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6444 | if (cls.IsRegister()) { |
| 6445 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6446 | } else { |
| 6447 | DCHECK(cls.IsStackSlot()) << cls; |
| 6448 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6449 | } |
| 6450 | __ j(kNotEqual, &loop); |
| 6451 | break; |
| 6452 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6453 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6454 | case TypeCheckKind::kClassHierarchyCheck: { |
| 6455 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6456 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6457 | __ Bind(&loop); |
| 6458 | if (cls.IsRegister()) { |
| 6459 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6460 | } else { |
| 6461 | DCHECK(cls.IsStackSlot()) << cls; |
| 6462 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6463 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6464 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6465 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6466 | // /* HeapReference<Class> */ temp = temp->super_class_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6467 | GenerateReferenceLoadOneRegister(instruction, temp_loc, super_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6468 | |
| 6469 | // If the class reference currently in `temp` is not null, jump |
| 6470 | // back at the beginning of the loop. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6471 | __ testl(temp, temp); |
| 6472 | __ j(kNotEqual, &loop); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6473 | // Otherwise, jump to the slow path to throw the exception. |
| 6474 | // |
| 6475 | // But before, move back the object's class into `temp` before |
| 6476 | // going into the slow path, as it has been overwritten in the |
| 6477 | // meantime. |
| 6478 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6479 | GenerateReferenceLoadTwoRegisters( |
| 6480 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6481 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6482 | break; |
| 6483 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6484 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6485 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6486 | // Do an exact check. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6487 | NearLabel check_non_primitive_component_type; |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6488 | if (cls.IsRegister()) { |
| 6489 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 6490 | } else { |
| 6491 | DCHECK(cls.IsStackSlot()) << cls; |
| 6492 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 6493 | } |
| 6494 | __ j(kEqual, &done); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6495 | |
| 6496 | // 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] | 6497 | // /* HeapReference<Class> */ temp = temp->component_type_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6498 | GenerateReferenceLoadOneRegister(instruction, temp_loc, component_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6499 | |
| 6500 | // If the component type is not null (i.e. the object is indeed |
| 6501 | // an array), jump to label `check_non_primitive_component_type` |
| 6502 | // to further check that this component type is not a primitive |
| 6503 | // type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6504 | __ testl(temp, temp); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6505 | __ j(kNotEqual, &check_non_primitive_component_type); |
| 6506 | // Otherwise, jump to the slow path to throw the exception. |
| 6507 | // |
| 6508 | // But before, move back the object's class into `temp` before |
| 6509 | // going into the slow path, as it has been overwritten in the |
| 6510 | // meantime. |
| 6511 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6512 | GenerateReferenceLoadTwoRegisters( |
| 6513 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6514 | __ jmp(type_check_slow_path->GetEntryLabel()); |
| 6515 | |
| 6516 | __ Bind(&check_non_primitive_component_type); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6517 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6518 | __ j(kEqual, &done); |
| 6519 | // Same comment as above regarding `temp` and the slow path. |
| 6520 | // /* HeapReference<Class> */ temp = obj->klass_ |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6521 | GenerateReferenceLoadTwoRegisters( |
| 6522 | instruction, temp_loc, obj_loc, class_offset, maybe_temp2_loc); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6523 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6524 | break; |
| 6525 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6526 | |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6527 | case TypeCheckKind::kUnresolvedCheck: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6528 | case TypeCheckKind::kInterfaceCheck: |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6529 | // We always go into the type check slow path for the unresolved |
| 6530 | // and interface check cases. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6531 | // |
| 6532 | // We cannot directly call the CheckCast runtime entry point |
| 6533 | // without resorting to a type checking slow path here (i.e. by |
| 6534 | // calling InvokeRuntime directly), as it would require to |
| 6535 | // assign fixed registers for the inputs of this HInstanceOf |
| 6536 | // instruction (following the runtime calling convention), which |
| 6537 | // might be cluttered by the potential first read barrier |
| 6538 | // emission at the beginning of this method. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6539 | // |
| 6540 | // TODO: Introduce a new runtime entry point taking the object |
| 6541 | // to test (instead of its class) as argument, and let it deal |
| 6542 | // with the read barrier issues. This will let us refactor this |
| 6543 | // case of the `switch` code as it was previously (with a direct |
| 6544 | // call to the runtime not using a type checking slow path). |
| 6545 | // This should also be beneficial for the other cases above. |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6546 | __ jmp(type_check_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6547 | break; |
| 6548 | } |
| 6549 | __ Bind(&done); |
| 6550 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6551 | __ Bind(type_check_slow_path->GetExitLabel()); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6552 | } |
| 6553 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6554 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 6555 | LocationSummary* locations = |
| 6556 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 6557 | InvokeRuntimeCallingConvention calling_convention; |
| 6558 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 6559 | } |
| 6560 | |
| 6561 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 6562 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 6563 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 6564 | instruction, |
| 6565 | instruction->GetDexPc(), |
| 6566 | nullptr); |
Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6567 | if (instruction->IsEnter()) { |
| 6568 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); |
| 6569 | } else { |
| 6570 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); |
| 6571 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6572 | } |
| 6573 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6574 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 6575 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 6576 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 6577 | |
| 6578 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6579 | LocationSummary* locations = |
| 6580 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 6581 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 6582 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 6583 | locations->SetInAt(0, Location::RequiresRegister()); |
| 6584 | locations->SetInAt(1, Location::Any()); |
| 6585 | locations->SetOut(Location::SameAsFirstInput()); |
| 6586 | } |
| 6587 | |
| 6588 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 6589 | HandleBitwiseOperation(instruction); |
| 6590 | } |
| 6591 | |
| 6592 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 6593 | HandleBitwiseOperation(instruction); |
| 6594 | } |
| 6595 | |
| 6596 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 6597 | HandleBitwiseOperation(instruction); |
| 6598 | } |
| 6599 | |
| 6600 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 6601 | LocationSummary* locations = instruction->GetLocations(); |
| 6602 | Location first = locations->InAt(0); |
| 6603 | Location second = locations->InAt(1); |
| 6604 | DCHECK(first.Equals(locations->Out())); |
| 6605 | |
| 6606 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 6607 | if (second.IsRegister()) { |
| 6608 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6609 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6610 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6611 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6612 | } else { |
| 6613 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6614 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6615 | } |
| 6616 | } else if (second.IsConstant()) { |
| 6617 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6618 | __ andl(first.AsRegister<Register>(), |
| 6619 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6620 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6621 | __ orl(first.AsRegister<Register>(), |
| 6622 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6623 | } else { |
| 6624 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6625 | __ xorl(first.AsRegister<Register>(), |
| 6626 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6627 | } |
| 6628 | } else { |
| 6629 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6630 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6631 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6632 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6633 | } else { |
| 6634 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6635 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6636 | } |
| 6637 | } |
| 6638 | } else { |
| 6639 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 6640 | if (second.IsRegisterPair()) { |
| 6641 | if (instruction->IsAnd()) { |
| 6642 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6643 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6644 | } else if (instruction->IsOr()) { |
| 6645 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6646 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6647 | } else { |
| 6648 | DCHECK(instruction->IsXor()); |
| 6649 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 6650 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 6651 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6652 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6653 | if (instruction->IsAnd()) { |
| 6654 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6655 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 6656 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6657 | } else if (instruction->IsOr()) { |
| 6658 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6659 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 6660 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6661 | } else { |
| 6662 | DCHECK(instruction->IsXor()); |
| 6663 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 6664 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 6665 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 6666 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6667 | } else { |
| 6668 | DCHECK(second.IsConstant()) << second; |
| 6669 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6670 | int32_t low_value = Low32Bits(value); |
| 6671 | int32_t high_value = High32Bits(value); |
| 6672 | Immediate low(low_value); |
| 6673 | Immediate high(high_value); |
| 6674 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 6675 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6676 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6677 | if (low_value == 0) { |
| 6678 | __ xorl(first_low, first_low); |
| 6679 | } else if (low_value != -1) { |
| 6680 | __ andl(first_low, low); |
| 6681 | } |
| 6682 | if (high_value == 0) { |
| 6683 | __ xorl(first_high, first_high); |
| 6684 | } else if (high_value != -1) { |
| 6685 | __ andl(first_high, high); |
| 6686 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6687 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6688 | if (low_value != 0) { |
| 6689 | __ orl(first_low, low); |
| 6690 | } |
| 6691 | if (high_value != 0) { |
| 6692 | __ orl(first_high, high); |
| 6693 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6694 | } else { |
| 6695 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6696 | if (low_value != 0) { |
| 6697 | __ xorl(first_low, low); |
| 6698 | } |
| 6699 | if (high_value != 0) { |
| 6700 | __ xorl(first_high, high); |
| 6701 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6702 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 6703 | } |
| 6704 | } |
| 6705 | } |
| 6706 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6707 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister(HInstruction* instruction, |
| 6708 | Location out, |
| 6709 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6710 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6711 | Register out_reg = out.AsRegister<Register>(); |
| 6712 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6713 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6714 | if (kUseBakerReadBarrier) { |
| 6715 | // Load with fast path based Baker's read barrier. |
| 6716 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6717 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6718 | instruction, out, out_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6719 | } else { |
| 6720 | // Load with slow path based read barrier. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6721 | // Save the value of `out` into `maybe_temp` before overwriting it |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6722 | // in the following move operation, as we will need it for the |
| 6723 | // read barrier below. |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6724 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6725 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6726 | __ movl(out_reg, Address(out_reg, offset)); |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6727 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6728 | } |
| 6729 | } else { |
| 6730 | // Plain load with no read barrier. |
| 6731 | // /* HeapReference<Object> */ out = *(out + offset) |
| 6732 | __ movl(out_reg, Address(out_reg, offset)); |
| 6733 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6734 | } |
| 6735 | } |
| 6736 | |
| 6737 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters(HInstruction* instruction, |
| 6738 | Location out, |
| 6739 | Location obj, |
| 6740 | uint32_t offset, |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6741 | Location maybe_temp) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6742 | Register out_reg = out.AsRegister<Register>(); |
| 6743 | Register obj_reg = obj.AsRegister<Register>(); |
| 6744 | if (kEmitCompilerReadBarrier) { |
| 6745 | if (kUseBakerReadBarrier) { |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6746 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6747 | // Load with fast path based Baker's read barrier. |
| 6748 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6749 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 6750 | instruction, out, obj_reg, offset, maybe_temp, /* needs_null_check */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6751 | } else { |
| 6752 | // Load with slow path based read barrier. |
| 6753 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6754 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6755 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); |
| 6756 | } |
| 6757 | } else { |
| 6758 | // Plain load with no read barrier. |
| 6759 | // /* HeapReference<Object> */ out = *(obj + offset) |
| 6760 | __ movl(out_reg, Address(obj_reg, offset)); |
| 6761 | __ MaybeUnpoisonHeapReference(out_reg); |
| 6762 | } |
| 6763 | } |
| 6764 | |
| 6765 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad(HInstruction* instruction, |
| 6766 | Location root, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6767 | const Address& address, |
| 6768 | Label* fixup_label) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6769 | Register root_reg = root.AsRegister<Register>(); |
| 6770 | if (kEmitCompilerReadBarrier) { |
| 6771 | if (kUseBakerReadBarrier) { |
| 6772 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when |
| 6773 | // Baker's read barrier are used: |
| 6774 | // |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6775 | // root = *address; |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6776 | // if (Thread::Current()->GetIsGcMarking()) { |
| 6777 | // root = ReadBarrier::Mark(root) |
| 6778 | // } |
| 6779 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6780 | // /* GcRoot<mirror::Object> */ root = *address |
| 6781 | __ movl(root_reg, address); |
| 6782 | if (fixup_label != nullptr) { |
| 6783 | __ Bind(fixup_label); |
| 6784 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6785 | static_assert( |
| 6786 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), |
| 6787 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " |
| 6788 | "have different sizes."); |
| 6789 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), |
| 6790 | "art::mirror::CompressedReference<mirror::Object> and int32_t " |
| 6791 | "have different sizes."); |
| 6792 | |
| 6793 | // Slow path used to mark the GC root `root`. |
| 6794 | SlowPathCode* slow_path = |
| 6795 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, root, root); |
| 6796 | codegen_->AddSlowPath(slow_path); |
| 6797 | |
| 6798 | __ fs()->cmpl(Address::Absolute(Thread::IsGcMarkingOffset<kX86WordSize>().Int32Value()), |
| 6799 | Immediate(0)); |
| 6800 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 6801 | __ Bind(slow_path->GetExitLabel()); |
| 6802 | } else { |
| 6803 | // GC root loaded through a slow path for read barriers other |
| 6804 | // than Baker's. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6805 | // /* GcRoot<mirror::Object>* */ root = address |
| 6806 | __ leal(root_reg, address); |
| 6807 | if (fixup_label != nullptr) { |
| 6808 | __ Bind(fixup_label); |
| 6809 | } |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6810 | // /* mirror::Object* */ root = root->Read() |
| 6811 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); |
| 6812 | } |
| 6813 | } else { |
| 6814 | // Plain GC root load with no read barrier. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6815 | // /* GcRoot<mirror::Object> */ root = *address |
| 6816 | __ movl(root_reg, address); |
| 6817 | if (fixup_label != nullptr) { |
| 6818 | __ Bind(fixup_label); |
| 6819 | } |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6820 | // Note that GC roots are not affected by heap poisoning, thus we |
| 6821 | // do not have to unpoison `root_reg` here. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6822 | } |
| 6823 | } |
| 6824 | |
| 6825 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6826 | Location ref, |
| 6827 | Register obj, |
| 6828 | uint32_t offset, |
| 6829 | Location temp, |
| 6830 | bool needs_null_check) { |
| 6831 | DCHECK(kEmitCompilerReadBarrier); |
| 6832 | DCHECK(kUseBakerReadBarrier); |
| 6833 | |
| 6834 | // /* HeapReference<Object> */ ref = *(obj + offset) |
| 6835 | Address src(obj, offset); |
| 6836 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6837 | } |
| 6838 | |
| 6839 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6840 | Location ref, |
| 6841 | Register obj, |
| 6842 | uint32_t data_offset, |
| 6843 | Location index, |
| 6844 | Location temp, |
| 6845 | bool needs_null_check) { |
| 6846 | DCHECK(kEmitCompilerReadBarrier); |
| 6847 | DCHECK(kUseBakerReadBarrier); |
| 6848 | |
| 6849 | // /* HeapReference<Object> */ ref = |
| 6850 | // *(obj + data_offset + index * sizeof(HeapReference<Object>)) |
| 6851 | Address src = index.IsConstant() ? |
| 6852 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset) : |
| 6853 | Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset); |
| 6854 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, temp, needs_null_check); |
| 6855 | } |
| 6856 | |
| 6857 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, |
| 6858 | Location ref, |
| 6859 | Register obj, |
| 6860 | const Address& src, |
| 6861 | Location temp, |
| 6862 | bool needs_null_check) { |
| 6863 | DCHECK(kEmitCompilerReadBarrier); |
| 6864 | DCHECK(kUseBakerReadBarrier); |
| 6865 | |
| 6866 | // In slow path based read barriers, the read barrier call is |
| 6867 | // inserted after the original load. However, in fast path based |
| 6868 | // Baker's read barriers, we need to perform the load of |
| 6869 | // mirror::Object::monitor_ *before* the original reference load. |
| 6870 | // This load-load ordering is required by the read barrier. |
| 6871 | // The fast path/slow path (for Baker's algorithm) should look like: |
| 6872 | // |
| 6873 | // uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); |
| 6874 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 6875 | // HeapReference<Object> ref = *src; // Original reference load. |
| 6876 | // bool is_gray = (rb_state == ReadBarrier::gray_ptr_); |
| 6877 | // if (is_gray) { |
| 6878 | // ref = ReadBarrier::Mark(ref); // Performed by runtime entrypoint slow path. |
| 6879 | // } |
| 6880 | // |
| 6881 | // Note: the original implementation in ReadBarrier::Barrier is |
| 6882 | // slightly more complex as: |
| 6883 | // - it implements the load-load fence using a data dependency on |
Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 6884 | // the high-bits of rb_state, which are expected to be all zeroes |
| 6885 | // (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, |
| 6886 | // which is a no-op thanks to the x86 memory model); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6887 | // - it performs additional checks that we do not do here for |
| 6888 | // performance reasons. |
| 6889 | |
| 6890 | Register ref_reg = ref.AsRegister<Register>(); |
| 6891 | Register temp_reg = temp.AsRegister<Register>(); |
| 6892 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 6893 | |
| 6894 | // /* int32_t */ monitor = obj->monitor_ |
| 6895 | __ movl(temp_reg, Address(obj, monitor_offset)); |
| 6896 | if (needs_null_check) { |
| 6897 | MaybeRecordImplicitNullCheck(instruction); |
| 6898 | } |
| 6899 | // /* LockWord */ lock_word = LockWord(monitor) |
| 6900 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 6901 | "art::LockWord and int32_t have different sizes."); |
| 6902 | // /* uint32_t */ rb_state = lock_word.ReadBarrierState() |
| 6903 | __ shrl(temp_reg, Immediate(LockWord::kReadBarrierStateShift)); |
| 6904 | __ andl(temp_reg, Immediate(LockWord::kReadBarrierStateMask)); |
| 6905 | static_assert( |
| 6906 | LockWord::kReadBarrierStateMask == ReadBarrier::rb_ptr_mask_, |
| 6907 | "art::LockWord::kReadBarrierStateMask is not equal to art::ReadBarrier::rb_ptr_mask_."); |
| 6908 | |
| 6909 | // Load fence to prevent load-load reordering. |
| 6910 | // Note that this is a no-op, thanks to the x86 memory model. |
| 6911 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 6912 | |
| 6913 | // The actual reference load. |
| 6914 | // /* HeapReference<Object> */ ref = *src |
| 6915 | __ movl(ref_reg, src); |
| 6916 | |
| 6917 | // Object* ref = ref_addr->AsMirrorPtr() |
| 6918 | __ MaybeUnpoisonHeapReference(ref_reg); |
| 6919 | |
| 6920 | // Slow path used to mark the object `ref` when it is gray. |
| 6921 | SlowPathCode* slow_path = |
| 6922 | new (GetGraph()->GetArena()) ReadBarrierMarkSlowPathX86(instruction, ref, ref); |
| 6923 | AddSlowPath(slow_path); |
| 6924 | |
| 6925 | // if (rb_state == ReadBarrier::gray_ptr_) |
| 6926 | // ref = ReadBarrier::Mark(ref); |
| 6927 | __ cmpl(temp_reg, Immediate(ReadBarrier::gray_ptr_)); |
| 6928 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 6929 | __ Bind(slow_path->GetExitLabel()); |
| 6930 | } |
| 6931 | |
| 6932 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, |
| 6933 | Location out, |
| 6934 | Location ref, |
| 6935 | Location obj, |
| 6936 | uint32_t offset, |
| 6937 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6938 | DCHECK(kEmitCompilerReadBarrier); |
| 6939 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6940 | // Insert a slow path based read barrier *after* the reference load. |
| 6941 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6942 | // If heap poisoning is enabled, the unpoisoning of the loaded |
| 6943 | // reference will be carried out by the runtime within the slow |
| 6944 | // path. |
| 6945 | // |
| 6946 | // Note that `ref` currently does not get unpoisoned (when heap |
| 6947 | // poisoning is enabled), which is alright as the `ref` argument is |
| 6948 | // not used by the artReadBarrierSlow entry point. |
| 6949 | // |
| 6950 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. |
| 6951 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
| 6952 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); |
| 6953 | AddSlowPath(slow_path); |
| 6954 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6955 | __ jmp(slow_path->GetEntryLabel()); |
| 6956 | __ Bind(slow_path->GetExitLabel()); |
| 6957 | } |
| 6958 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6959 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, |
| 6960 | Location out, |
| 6961 | Location ref, |
| 6962 | Location obj, |
| 6963 | uint32_t offset, |
| 6964 | Location index) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6965 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6966 | // Baker's read barriers shall be handled by the fast path |
| 6967 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). |
| 6968 | DCHECK(!kUseBakerReadBarrier); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6969 | // If heap poisoning is enabled, unpoisoning will be taken care of |
| 6970 | // by the runtime within the slow path. |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6971 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6972 | } else if (kPoisonHeapReferences) { |
| 6973 | __ UnpoisonHeapReference(out.AsRegister<Register>()); |
| 6974 | } |
| 6975 | } |
| 6976 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6977 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, |
| 6978 | Location out, |
| 6979 | Location root) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6980 | DCHECK(kEmitCompilerReadBarrier); |
| 6981 | |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6982 | // Insert a slow path based read barrier *after* the GC root load. |
| 6983 | // |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6984 | // Note that GC roots are not affected by heap poisoning, so we do |
| 6985 | // not need to do anything special for this here. |
| 6986 | SlowPathCode* slow_path = |
| 6987 | new (GetGraph()->GetArena()) ReadBarrierForRootSlowPathX86(instruction, out, root); |
| 6988 | AddSlowPath(slow_path); |
| 6989 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6990 | __ jmp(slow_path->GetEntryLabel()); |
| 6991 | __ Bind(slow_path->GetExitLabel()); |
| 6992 | } |
| 6993 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6994 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6995 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6996 | LOG(FATAL) << "Unreachable"; |
| 6997 | } |
| 6998 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6999 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7000 | // Nothing to do, this should be removed during prepare for register allocator. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7001 | LOG(FATAL) << "Unreachable"; |
| 7002 | } |
| 7003 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7004 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 7005 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7006 | LocationSummary* locations = |
| 7007 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7008 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7009 | } |
| 7010 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7011 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, |
| 7012 | int32_t lower_bound, |
| 7013 | uint32_t num_entries, |
| 7014 | HBasicBlock* switch_block, |
| 7015 | HBasicBlock* default_block) { |
| 7016 | // Figure out the correct compare values and jump conditions. |
| 7017 | // Handle the first compare/branch as a special case because it might |
| 7018 | // jump to the default case. |
| 7019 | DCHECK_GT(num_entries, 2u); |
| 7020 | Condition first_condition; |
| 7021 | uint32_t index; |
| 7022 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); |
| 7023 | if (lower_bound != 0) { |
| 7024 | first_condition = kLess; |
| 7025 | __ cmpl(value_reg, Immediate(lower_bound)); |
| 7026 | __ j(first_condition, codegen_->GetLabelOf(default_block)); |
| 7027 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7028 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7029 | index = 1; |
| 7030 | } else { |
| 7031 | // Handle all the compare/jumps below. |
| 7032 | first_condition = kBelow; |
| 7033 | index = 0; |
| 7034 | } |
| 7035 | |
| 7036 | // Handle the rest of the compare/jumps. |
| 7037 | for (; index + 1 < num_entries; index += 2) { |
| 7038 | int32_t compare_to_value = lower_bound + index + 1; |
| 7039 | __ cmpl(value_reg, Immediate(compare_to_value)); |
| 7040 | // Jump to successors[index] if value < case_value[index]. |
| 7041 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); |
| 7042 | // Jump to successors[index + 1] if value == case_value[index + 1]. |
| 7043 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); |
| 7044 | } |
| 7045 | |
| 7046 | if (index != num_entries) { |
| 7047 | // There are an odd number of entries. Handle the last one. |
| 7048 | DCHECK_EQ(index + 1, num_entries); |
| 7049 | __ cmpl(value_reg, Immediate(lower_bound + index)); |
| 7050 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7051 | } |
| 7052 | |
| 7053 | // And the default for any other value. |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7054 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { |
| 7055 | __ jmp(codegen_->GetLabelOf(default_block)); |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7056 | } |
| 7057 | } |
| 7058 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7059 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 7060 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 7061 | uint32_t num_entries = switch_instr->GetNumEntries(); |
| 7062 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7063 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7064 | |
| 7065 | GenPackedSwitchWithCompares(value_reg, |
| 7066 | lower_bound, |
| 7067 | num_entries, |
| 7068 | switch_instr->GetBlock(), |
| 7069 | switch_instr->GetDefaultBlock()); |
| 7070 | } |
| 7071 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7072 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7073 | LocationSummary* locations = |
| 7074 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 7075 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7076 | |
| 7077 | // Constant area pointer. |
| 7078 | locations->SetInAt(1, Location::RequiresRegister()); |
| 7079 | |
| 7080 | // And the temporary we need. |
| 7081 | locations->AddTemp(Location::RequiresRegister()); |
| 7082 | } |
| 7083 | |
| 7084 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { |
| 7085 | int32_t lower_bound = switch_instr->GetStartValue(); |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7086 | uint32_t num_entries = switch_instr->GetNumEntries(); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7087 | LocationSummary* locations = switch_instr->GetLocations(); |
| 7088 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 7089 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 7090 | |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7091 | if (num_entries <= kPackedSwitchJumpTableThreshold) { |
| 7092 | GenPackedSwitchWithCompares(value_reg, |
| 7093 | lower_bound, |
| 7094 | num_entries, |
| 7095 | switch_instr->GetBlock(), |
| 7096 | default_block); |
| 7097 | return; |
| 7098 | } |
| 7099 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7100 | // Optimizing has a jump area. |
| 7101 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); |
| 7102 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
| 7103 | |
| 7104 | // Remove the bias, if needed. |
| 7105 | if (lower_bound != 0) { |
| 7106 | __ leal(temp_reg, Address(value_reg, -lower_bound)); |
| 7107 | value_reg = temp_reg; |
| 7108 | } |
| 7109 | |
| 7110 | // Is the value in range? |
Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7111 | DCHECK_GE(num_entries, 1u); |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7112 | __ cmpl(value_reg, Immediate(num_entries - 1)); |
| 7113 | __ j(kAbove, codegen_->GetLabelOf(default_block)); |
| 7114 | |
| 7115 | // We are in the range of the table. |
| 7116 | // Load (target-constant_area) from the jump table, indexing by the value. |
| 7117 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); |
| 7118 | |
| 7119 | // Compute the actual target address by adding in constant_area. |
| 7120 | __ addl(temp_reg, constant_area); |
| 7121 | |
| 7122 | // And jump. |
| 7123 | __ jmp(temp_reg); |
| 7124 | } |
| 7125 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7126 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 7127 | HX86ComputeBaseMethodAddress* insn) { |
| 7128 | LocationSummary* locations = |
| 7129 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7130 | locations->SetOut(Location::RequiresRegister()); |
| 7131 | } |
| 7132 | |
| 7133 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 7134 | HX86ComputeBaseMethodAddress* insn) { |
| 7135 | LocationSummary* locations = insn->GetLocations(); |
| 7136 | Register reg = locations->Out().AsRegister<Register>(); |
| 7137 | |
| 7138 | // Generate call to next instruction. |
| 7139 | Label next_instruction; |
| 7140 | __ call(&next_instruction); |
| 7141 | __ Bind(&next_instruction); |
| 7142 | |
| 7143 | // Remember this offset for later use with constant area. |
| 7144 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 7145 | |
| 7146 | // Grab the return address off the stack. |
| 7147 | __ popl(reg); |
| 7148 | } |
| 7149 | |
| 7150 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 7151 | HX86LoadFromConstantTable* insn) { |
| 7152 | LocationSummary* locations = |
| 7153 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 7154 | |
| 7155 | locations->SetInAt(0, Location::RequiresRegister()); |
| 7156 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 7157 | |
| 7158 | // If we don't need to be materialized, we only need the inputs to be set. |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7159 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7160 | return; |
| 7161 | } |
| 7162 | |
| 7163 | switch (insn->GetType()) { |
| 7164 | case Primitive::kPrimFloat: |
| 7165 | case Primitive::kPrimDouble: |
| 7166 | locations->SetOut(Location::RequiresFpuRegister()); |
| 7167 | break; |
| 7168 | |
| 7169 | case Primitive::kPrimInt: |
| 7170 | locations->SetOut(Location::RequiresRegister()); |
| 7171 | break; |
| 7172 | |
| 7173 | default: |
| 7174 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7175 | } |
| 7176 | } |
| 7177 | |
| 7178 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 7179 | if (insn->IsEmittedAtUseSite()) { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7180 | return; |
| 7181 | } |
| 7182 | |
| 7183 | LocationSummary* locations = insn->GetLocations(); |
| 7184 | Location out = locations->Out(); |
| 7185 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 7186 | HConstant *value = insn->GetConstant(); |
| 7187 | |
| 7188 | switch (insn->GetType()) { |
| 7189 | case Primitive::kPrimFloat: |
| 7190 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 7191 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 7192 | break; |
| 7193 | |
| 7194 | case Primitive::kPrimDouble: |
| 7195 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 7196 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 7197 | break; |
| 7198 | |
| 7199 | case Primitive::kPrimInt: |
| 7200 | __ movl(out.AsRegister<Register>(), |
| 7201 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 7202 | break; |
| 7203 | |
| 7204 | default: |
| 7205 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 7206 | } |
| 7207 | } |
| 7208 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7209 | /** |
| 7210 | * Class to handle late fixup of offsets into constant area. |
| 7211 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 7212 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7213 | public: |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7214 | RIPFixup(CodeGeneratorX86& codegen, size_t offset) |
| 7215 | : codegen_(&codegen), offset_into_constant_area_(offset) {} |
| 7216 | |
| 7217 | protected: |
| 7218 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } |
| 7219 | |
| 7220 | CodeGeneratorX86* codegen_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7221 | |
| 7222 | private: |
| 7223 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 7224 | // Patch the correct offset for the instruction. The place to patch is the |
| 7225 | // last 4 bytes of the instruction. |
| 7226 | // The value to patch is the distance from the offset in the constant area |
| 7227 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7228 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; |
| 7229 | int32_t relative_position = constant_offset - codegen_->GetMethodAddressOffset();; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7230 | |
| 7231 | // Patch in the right value. |
| 7232 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 7233 | } |
| 7234 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7235 | // Location in constant area that the fixup refers to. |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7236 | int32_t offset_into_constant_area_; |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7237 | }; |
| 7238 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7239 | /** |
| 7240 | * Class to handle late fixup of offsets to a jump table that will be created in the |
| 7241 | * constant area. |
| 7242 | */ |
| 7243 | class JumpTableRIPFixup : public RIPFixup { |
| 7244 | public: |
| 7245 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) |
| 7246 | : RIPFixup(codegen, static_cast<size_t>(-1)), switch_instr_(switch_instr) {} |
| 7247 | |
| 7248 | void CreateJumpTable() { |
| 7249 | X86Assembler* assembler = codegen_->GetAssembler(); |
| 7250 | |
| 7251 | // Ensure that the reference to the jump table has the correct offset. |
| 7252 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); |
| 7253 | SetOffset(offset_in_constant_table); |
| 7254 | |
| 7255 | // The label values in the jump table are computed relative to the |
| 7256 | // instruction addressing the constant area. |
| 7257 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(); |
| 7258 | |
| 7259 | // Populate the jump table with the correct values for the jump table. |
| 7260 | int32_t num_entries = switch_instr_->GetNumEntries(); |
| 7261 | HBasicBlock* block = switch_instr_->GetBlock(); |
| 7262 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); |
| 7263 | // The value that we want is the target offset - the position of the table. |
| 7264 | for (int32_t i = 0; i < num_entries; i++) { |
| 7265 | HBasicBlock* b = successors[i]; |
| 7266 | Label* l = codegen_->GetLabelOf(b); |
| 7267 | DCHECK(l->IsBound()); |
| 7268 | int32_t offset_to_block = l->Position() - relative_offset; |
| 7269 | assembler->AppendInt32(offset_to_block); |
| 7270 | } |
| 7271 | } |
| 7272 | |
| 7273 | private: |
| 7274 | const HX86PackedSwitch* switch_instr_; |
| 7275 | }; |
| 7276 | |
| 7277 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 7278 | // Generate the constant area if needed. |
| 7279 | X86Assembler* assembler = GetAssembler(); |
| 7280 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { |
| 7281 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 7282 | // byte values. |
| 7283 | assembler->Align(4, 0); |
| 7284 | constant_area_start_ = assembler->CodeSize(); |
| 7285 | |
| 7286 | // Populate any jump tables. |
| 7287 | for (auto jump_table : fixups_to_jump_tables_) { |
| 7288 | jump_table->CreateJumpTable(); |
| 7289 | } |
| 7290 | |
| 7291 | // And now add the constant area to the generated code. |
| 7292 | assembler->AddConstantArea(); |
| 7293 | } |
| 7294 | |
| 7295 | // And finish up. |
| 7296 | CodeGenerator::Finalize(allocator); |
| 7297 | } |
| 7298 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7299 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 7300 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 7301 | return Address(reg, kDummy32BitOffset, fixup); |
| 7302 | } |
| 7303 | |
| 7304 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 7305 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 7306 | return Address(reg, kDummy32BitOffset, fixup); |
| 7307 | } |
| 7308 | |
| 7309 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 7310 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 7311 | return Address(reg, kDummy32BitOffset, fixup); |
| 7312 | } |
| 7313 | |
| 7314 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 7315 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 7316 | return Address(reg, kDummy32BitOffset, fixup); |
| 7317 | } |
| 7318 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 7319 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { |
| 7320 | if (value == 0) { |
| 7321 | __ xorl(dest, dest); |
| 7322 | } else { |
| 7323 | __ movl(dest, Immediate(value)); |
| 7324 | } |
| 7325 | } |
| 7326 | |
| 7327 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { |
| 7328 | if (value == 0) { |
| 7329 | __ testl(dest, dest); |
| 7330 | } else { |
| 7331 | __ cmpl(dest, Immediate(value)); |
| 7332 | } |
| 7333 | } |
| 7334 | |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 7335 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, |
| 7336 | Register reg, |
| 7337 | Register value) { |
| 7338 | // Create a fixup to be used to create and address the jump table. |
| 7339 | JumpTableRIPFixup* table_fixup = |
| 7340 | new (GetGraph()->GetArena()) JumpTableRIPFixup(*this, switch_instr); |
| 7341 | |
| 7342 | // We have to populate the jump tables. |
| 7343 | fixups_to_jump_tables_.push_back(table_fixup); |
| 7344 | |
| 7345 | // We want a scaled address, as we are extracting the correct offset from the table. |
| 7346 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); |
| 7347 | } |
| 7348 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7349 | // TODO: target as memory. |
| 7350 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 7351 | if (!target.IsValid()) { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7352 | DCHECK_EQ(type, Primitive::kPrimVoid); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 7353 | return; |
| 7354 | } |
| 7355 | |
| 7356 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 7357 | |
| 7358 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 7359 | if (target.Equals(return_loc)) { |
| 7360 | return; |
| 7361 | } |
| 7362 | |
| 7363 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 7364 | // with the else branch. |
| 7365 | if (type == Primitive::kPrimLong) { |
| 7366 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7367 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 7368 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 7369 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7370 | } else { |
| 7371 | // Let the parallel move resolver take care of all of this. |
| 7372 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 7373 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 7374 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 7375 | } |
| 7376 | } |
| 7377 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 7378 | #undef __ |
| 7379 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7380 | } // namespace x86 |
| 7381 | } // namespace art |