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" |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 22 | #include "constant_area_fixups_x86.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 23 | #include "entrypoints/quick/quick_entrypoints.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 24 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 25 | #include "gc/accounting/card_table.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 26 | #include "intrinsics.h" |
| 27 | #include "intrinsics_x86.h" |
Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 28 | #include "mirror/array-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/class-inl.h" |
Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 30 | #include "thread.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 31 | #include "utils/assembler.h" |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 32 | #include "utils/stack_checks.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 33 | #include "utils/x86/assembler_x86.h" |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 34 | #include "utils/x86/managed_register_x86.h" |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 36 | namespace art { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 37 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 38 | namespace x86 { |
| 39 | |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 40 | static constexpr int kCurrentMethodStackOffset = 0; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 41 | static constexpr Register kMethodRegisterArgument = EAX; |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 42 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 43 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 44 | |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 45 | static constexpr int kC2ConditionMask = 0x400; |
| 46 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 47 | static constexpr int kFakeReturnRegister = Register(8); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 48 | |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 49 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 50 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86WordSize, x).Int32Value() |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 51 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 52 | class NullCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 53 | public: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 54 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 55 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 56 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 57 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 58 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 59 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 60 | // Live registers will be restored in the catch block if caught. |
| 61 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 62 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 63 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowNullPointer), |
| 64 | instruction_, |
| 65 | instruction_->GetDexPc(), |
| 66 | this); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 69 | bool IsFatal() const OVERRIDE { return true; } |
| 70 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 71 | const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathX86"; } |
| 72 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 73 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 74 | HNullCheck* const instruction_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); |
| 76 | }; |
| 77 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 78 | class DivZeroCheckSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 79 | public: |
| 80 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {} |
| 81 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 82 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 83 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 84 | __ Bind(GetEntryLabel()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 85 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 86 | // Live registers will be restored in the catch block if caught. |
| 87 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 88 | } |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 89 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowDivZero), |
| 90 | instruction_, |
| 91 | instruction_->GetDexPc(), |
| 92 | this); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 95 | bool IsFatal() const OVERRIDE { return true; } |
| 96 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 97 | const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathX86"; } |
| 98 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 99 | private: |
| 100 | HDivZeroCheck* const instruction_; |
| 101 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); |
| 102 | }; |
| 103 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 104 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 105 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 106 | DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {} |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 107 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 108 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 109 | __ Bind(GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 110 | if (is_div_) { |
| 111 | __ negl(reg_); |
| 112 | } else { |
| 113 | __ movl(reg_, Immediate(0)); |
| 114 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 115 | __ jmp(GetExitLabel()); |
| 116 | } |
| 117 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 118 | const char* GetDescription() const OVERRIDE { return "DivRemMinusOneSlowPathX86"; } |
| 119 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 | private: |
| 121 | Register reg_; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 122 | bool is_div_; |
| 123 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 126 | class BoundsCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 127 | public: |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 128 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : instruction_(instruction) {} |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 129 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 130 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 131 | LocationSummary* locations = instruction_->GetLocations(); |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 132 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 133 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 134 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 135 | // move resolver. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 136 | if (instruction_->CanThrowIntoCatchBlock()) { |
| 137 | // Live registers will be restored in the catch block if caught. |
| 138 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
| 139 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 141 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 142 | locations->InAt(0), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 143 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 144 | Primitive::kPrimInt, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 145 | locations->InAt(1), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 146 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 147 | Primitive::kPrimInt); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 148 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pThrowArrayBounds), |
| 149 | instruction_, |
| 150 | instruction_->GetDexPc(), |
| 151 | this); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 154 | bool IsFatal() const OVERRIDE { return true; } |
| 155 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 156 | const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathX86"; } |
| 157 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 158 | private: |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 159 | HBoundsCheck* const instruction_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 160 | |
| 161 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); |
| 162 | }; |
| 163 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 164 | class SuspendCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 165 | public: |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 166 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 167 | : instruction_(instruction), successor_(successor) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 168 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 169 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 170 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 172 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 173 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pTestSuspend), |
| 174 | instruction_, |
| 175 | instruction_->GetDexPc(), |
| 176 | this); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 177 | RestoreLiveRegisters(codegen, instruction_->GetLocations()); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 178 | if (successor_ == nullptr) { |
| 179 | __ jmp(GetReturnLabel()); |
| 180 | } else { |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 181 | __ jmp(x86_codegen->GetLabelOf(successor_)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 182 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 185 | Label* GetReturnLabel() { |
| 186 | DCHECK(successor_ == nullptr); |
| 187 | return &return_label_; |
| 188 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 189 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 190 | HBasicBlock* GetSuccessor() const { |
| 191 | return successor_; |
| 192 | } |
| 193 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 194 | const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathX86"; } |
| 195 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 196 | private: |
| 197 | HSuspendCheck* const instruction_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 198 | HBasicBlock* const successor_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 199 | Label return_label_; |
| 200 | |
| 201 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); |
| 202 | }; |
| 203 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 204 | class LoadStringSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 205 | public: |
| 206 | explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {} |
| 207 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 208 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 209 | LocationSummary* locations = instruction_->GetLocations(); |
| 210 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
| 211 | |
| 212 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 213 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 214 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 215 | |
| 216 | InvokeRuntimeCallingConvention calling_convention; |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 217 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction_->GetStringIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 218 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pResolveString), |
| 219 | instruction_, |
| 220 | instruction_->GetDexPc(), |
| 221 | this); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 222 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 223 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 224 | |
| 225 | __ jmp(GetExitLabel()); |
| 226 | } |
| 227 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 228 | const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathX86"; } |
| 229 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 230 | private: |
| 231 | HLoadString* const instruction_; |
| 232 | |
| 233 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); |
| 234 | }; |
| 235 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 236 | class LoadClassSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 237 | public: |
| 238 | LoadClassSlowPathX86(HLoadClass* cls, |
| 239 | HInstruction* at, |
| 240 | uint32_t dex_pc, |
| 241 | bool do_clinit) |
| 242 | : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) { |
| 243 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); |
| 244 | } |
| 245 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 246 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 247 | LocationSummary* locations = at_->GetLocations(); |
| 248 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 249 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 250 | SaveLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 251 | |
| 252 | InvokeRuntimeCallingConvention calling_convention; |
| 253 | __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex())); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 254 | x86_codegen->InvokeRuntime(do_clinit_ ? QUICK_ENTRY_POINT(pInitializeStaticStorage) |
| 255 | : QUICK_ENTRY_POINT(pInitializeType), |
| 256 | at_, dex_pc_, this); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 257 | |
| 258 | // Move the class to the desired location. |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 259 | Location out = locations->Out(); |
| 260 | if (out.IsValid()) { |
| 261 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 262 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 263 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 264 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 265 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | __ jmp(GetExitLabel()); |
| 267 | } |
| 268 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 269 | const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathX86"; } |
| 270 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | private: |
| 272 | // The class this slow path will load. |
| 273 | HLoadClass* const cls_; |
| 274 | |
| 275 | // The instruction where this slow path is happening. |
| 276 | // (Might be the load class or an initialization check). |
| 277 | HInstruction* const at_; |
| 278 | |
| 279 | // The dex PC of `at_`. |
| 280 | const uint32_t dex_pc_; |
| 281 | |
| 282 | // Whether to initialize the class. |
| 283 | const bool do_clinit_; |
| 284 | |
| 285 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); |
| 286 | }; |
| 287 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 288 | class TypeCheckSlowPathX86 : public SlowPathCode { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 289 | public: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 290 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) |
| 291 | : instruction_(instruction), is_fatal_(is_fatal) {} |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 292 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 293 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 294 | LocationSummary* locations = instruction_->GetLocations(); |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 295 | Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) |
| 296 | : locations->Out(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 297 | DCHECK(instruction_->IsCheckCast() |
| 298 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 299 | |
| 300 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 301 | __ Bind(GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 302 | |
| 303 | if (instruction_->IsCheckCast()) { |
| 304 | // The codegen for the instruction overwrites `temp`, so put it back in place. |
| 305 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 306 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 307 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 308 | __ movl(temp, Address(obj, class_offset)); |
| 309 | __ MaybeUnpoisonHeapReference(temp); |
| 310 | } |
| 311 | |
| 312 | if (!is_fatal_) { |
| 313 | SaveLiveRegisters(codegen, locations); |
| 314 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 315 | |
| 316 | // We're moving two locations to locations that could overlap, so we need a parallel |
| 317 | // move resolver. |
| 318 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 319 | x86_codegen->EmitParallelMoves( |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 320 | locations->InAt(1), |
Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 321 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 322 | Primitive::kPrimNot, |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 323 | object_class, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 324 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 325 | Primitive::kPrimNot); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 327 | if (instruction_->IsInstanceOf()) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 328 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 329 | instruction_, |
| 330 | instruction_->GetDexPc(), |
| 331 | this); |
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); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 340 | if (!is_fatal_) { |
| 341 | if (instruction_->IsInstanceOf()) { |
| 342 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); |
| 343 | } |
| 344 | RestoreLiveRegisters(codegen, locations); |
Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 345 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 346 | __ jmp(GetExitLabel()); |
| 347 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 350 | const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathX86"; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 351 | bool IsFatal() const OVERRIDE { return is_fatal_; } |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 352 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 353 | private: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 354 | HInstruction* const instruction_; |
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: |
| 362 | explicit DeoptimizationSlowPathX86(HInstruction* instruction) |
| 363 | : instruction_(instruction) {} |
| 364 | |
| 365 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
Alexandre Rames | 9859620 | 2015-08-19 11:33:36 +0100 | [diff] [blame] | 366 | DCHECK(instruction_->IsDeoptimize()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 367 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 368 | __ Bind(GetEntryLabel()); |
| 369 | SaveLiveRegisters(codegen, instruction_->GetLocations()); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 370 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pDeoptimize), |
| 371 | instruction_, |
| 372 | instruction_->GetDexPc(), |
| 373 | this); |
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: |
| 379 | HInstruction* const instruction_; |
| 380 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); |
| 381 | }; |
| 382 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 383 | class ArraySetSlowPathX86 : public SlowPathCode { |
| 384 | public: |
| 385 | explicit ArraySetSlowPathX86(HInstruction* instruction) : instruction_(instruction) {} |
| 386 | |
| 387 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 388 | LocationSummary* locations = instruction_->GetLocations(); |
| 389 | __ Bind(GetEntryLabel()); |
| 390 | SaveLiveRegisters(codegen, locations); |
| 391 | |
| 392 | InvokeRuntimeCallingConvention calling_convention; |
| 393 | HParallelMove parallel_move(codegen->GetGraph()->GetArena()); |
| 394 | parallel_move.AddMove( |
| 395 | locations->InAt(0), |
| 396 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), |
| 397 | Primitive::kPrimNot, |
| 398 | nullptr); |
| 399 | parallel_move.AddMove( |
| 400 | locations->InAt(1), |
| 401 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), |
| 402 | Primitive::kPrimInt, |
| 403 | nullptr); |
| 404 | parallel_move.AddMove( |
| 405 | locations->InAt(2), |
| 406 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), |
| 407 | Primitive::kPrimNot, |
| 408 | nullptr); |
| 409 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 410 | |
| 411 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 412 | x86_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject), |
| 413 | instruction_, |
| 414 | instruction_->GetDexPc(), |
| 415 | this); |
| 416 | RestoreLiveRegisters(codegen, locations); |
| 417 | __ jmp(GetExitLabel()); |
| 418 | } |
| 419 | |
| 420 | const char* GetDescription() const OVERRIDE { return "ArraySetSlowPathX86"; } |
| 421 | |
| 422 | private: |
| 423 | HInstruction* const instruction_; |
| 424 | |
| 425 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); |
| 426 | }; |
| 427 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 428 | #undef __ |
Roland Levillain | 62a46b2 | 2015-06-01 18:24:13 +0100 | [diff] [blame] | 429 | #define __ down_cast<X86Assembler*>(GetAssembler())-> |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 430 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 431 | inline Condition X86SignedCondition(IfCondition cond) { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 432 | switch (cond) { |
| 433 | case kCondEQ: return kEqual; |
| 434 | case kCondNE: return kNotEqual; |
| 435 | case kCondLT: return kLess; |
| 436 | case kCondLE: return kLessEqual; |
| 437 | case kCondGT: return kGreater; |
| 438 | case kCondGE: return kGreaterEqual; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 439 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 440 | LOG(FATAL) << "Unreachable"; |
| 441 | UNREACHABLE(); |
| 442 | } |
| 443 | |
| 444 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { |
| 445 | switch (cond) { |
| 446 | case kCondEQ: return kEqual; |
| 447 | case kCondNE: return kNotEqual; |
| 448 | case kCondLT: return kBelow; |
| 449 | case kCondLE: return kBelowEqual; |
| 450 | case kCondGT: return kAbove; |
| 451 | case kCondGE: return kAboveEqual; |
| 452 | } |
| 453 | LOG(FATAL) << "Unreachable"; |
| 454 | UNREACHABLE(); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 457 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 458 | stream << Register(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { |
David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 462 | stream << XmmRegister(reg); |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 465 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 466 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); |
| 467 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 468 | } |
| 469 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 470 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { |
| 471 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); |
| 472 | return kX86WordSize; |
Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 473 | } |
| 474 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 475 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 476 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); |
| 477 | return GetFloatingPointSpillSlotSize(); |
| 478 | } |
| 479 | |
| 480 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { |
| 481 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); |
| 482 | return GetFloatingPointSpillSlotSize(); |
| 483 | } |
| 484 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 485 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, |
| 486 | HInstruction* instruction, |
| 487 | uint32_t dex_pc, |
| 488 | SlowPathCode* slow_path) { |
| 489 | InvokeRuntime(GetThreadOffset<kX86WordSize>(entrypoint).Int32Value(), |
| 490 | instruction, |
| 491 | dex_pc, |
| 492 | slow_path); |
| 493 | } |
| 494 | |
| 495 | void CodeGeneratorX86::InvokeRuntime(int32_t entry_point_offset, |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 496 | HInstruction* instruction, |
| 497 | uint32_t dex_pc, |
| 498 | SlowPathCode* slow_path) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 499 | ValidateInvokeRuntime(instruction, slow_path); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 500 | __ fs()->call(Address::Absolute(entry_point_offset)); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 501 | RecordPcInfo(instruction, dex_pc, slow_path); |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 502 | } |
| 503 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 504 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, |
| 505 | const X86InstructionSetFeatures& isa_features, |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 506 | const CompilerOptions& compiler_options, |
| 507 | OptimizingCompilerStats* stats) |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 508 | : CodeGenerator(graph, |
| 509 | kNumberOfCpuRegisters, |
| 510 | kNumberOfXmmRegisters, |
| 511 | kNumberOfRegisterPairs, |
| 512 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), |
| 513 | arraysize(kCoreCalleeSaves)) |
| 514 | | (1 << kFakeReturnRegister), |
Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 515 | 0, |
| 516 | compiler_options, |
| 517 | stats), |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 518 | block_labels_(nullptr), |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 519 | location_builder_(graph, this), |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 520 | instruction_visitor_(graph, this), |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 521 | move_resolver_(graph->GetArena(), this), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 522 | isa_features_(isa_features), |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 523 | method_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)), |
| 524 | relative_call_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)) { |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 525 | // Use a fake return address register to mimic Quick. |
| 526 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 527 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 528 | |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 529 | Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 530 | switch (type) { |
| 531 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 532 | size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 533 | X86ManagedRegister pair = |
| 534 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg)); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 535 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]); |
| 536 | DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]); |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 537 | blocked_core_registers_[pair.AsRegisterPairLow()] = true; |
| 538 | blocked_core_registers_[pair.AsRegisterPairHigh()] = true; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 539 | UpdateBlockedPairRegisters(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 540 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | case Primitive::kPrimByte: |
| 544 | case Primitive::kPrimBoolean: |
| 545 | case Primitive::kPrimChar: |
| 546 | case Primitive::kPrimShort: |
| 547 | case Primitive::kPrimInt: |
| 548 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 549 | Register reg = static_cast<Register>( |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 550 | FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 551 | // Block all register pairs that contain `reg`. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 552 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 553 | X86ManagedRegister current = |
| 554 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 555 | if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 556 | blocked_register_pairs_[i] = true; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 557 | } |
| 558 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 559 | return Location::RegisterLocation(reg); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 563 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 564 | return Location::FpuRegisterLocation( |
| 565 | FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 566 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 567 | |
| 568 | case Primitive::kPrimVoid: |
| 569 | LOG(FATAL) << "Unreachable type " << type; |
| 570 | } |
| 571 | |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 572 | return Location(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 573 | } |
| 574 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 575 | void CodeGeneratorX86::SetupBlockedRegisters(bool is_baseline) const { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 576 | // Don't allocate the dalvik style register pair passing. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 577 | blocked_register_pairs_[ECX_EDX] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 578 | |
| 579 | // Stack register is always reserved. |
Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 580 | blocked_core_registers_[ESP] = true; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 581 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 582 | if (is_baseline) { |
| 583 | blocked_core_registers_[EBP] = true; |
| 584 | blocked_core_registers_[ESI] = true; |
| 585 | blocked_core_registers_[EDI] = true; |
| 586 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 587 | |
| 588 | UpdateBlockedPairRegisters(); |
| 589 | } |
| 590 | |
| 591 | void CodeGeneratorX86::UpdateBlockedPairRegisters() const { |
| 592 | for (int i = 0; i < kNumberOfRegisterPairs; i++) { |
| 593 | X86ManagedRegister current = |
| 594 | X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i)); |
| 595 | if (blocked_core_registers_[current.AsRegisterPairLow()] |
| 596 | || blocked_core_registers_[current.AsRegisterPairHigh()]) { |
| 597 | blocked_register_pairs_[i] = true; |
| 598 | } |
| 599 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 600 | } |
| 601 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 602 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) |
| 603 | : HGraphVisitor(graph), |
| 604 | assembler_(codegen->GetAssembler()), |
| 605 | codegen_(codegen) {} |
| 606 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 607 | static dwarf::Reg DWARFReg(Register reg) { |
David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 608 | return dwarf::Reg::X86Core(static_cast<int>(reg)); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 609 | } |
| 610 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 611 | void CodeGeneratorX86::GenerateFrameEntry() { |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 612 | __ cfi().SetCurrentCFAOffset(kX86WordSize); // return address |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 613 | __ Bind(&frame_entry_label_); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 614 | bool skip_overflow_check = |
| 615 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 616 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); |
Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 617 | |
Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 618 | if (!skip_overflow_check) { |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 619 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86)))); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 620 | RecordPcInfo(nullptr, 0); |
Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 621 | } |
| 622 | |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 623 | if (HasEmptyFrame()) { |
| 624 | return; |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 625 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 626 | |
| 627 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { |
| 628 | Register reg = kCoreCalleeSaves[i]; |
| 629 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 630 | __ pushl(reg); |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 631 | __ cfi().AdjustCFAOffset(kX86WordSize); |
| 632 | __ cfi().RelOffset(DWARFReg(reg), 0); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 636 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 637 | __ subl(ESP, Immediate(adjust)); |
| 638 | __ cfi().AdjustCFAOffset(adjust); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 639 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | void CodeGeneratorX86::GenerateFrameExit() { |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 643 | __ cfi().RememberState(); |
| 644 | if (!HasEmptyFrame()) { |
| 645 | int adjust = GetFrameSize() - FrameEntrySpillSize(); |
| 646 | __ addl(ESP, Immediate(adjust)); |
| 647 | __ cfi().AdjustCFAOffset(-adjust); |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 648 | |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 649 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { |
| 650 | Register reg = kCoreCalleeSaves[i]; |
| 651 | if (allocated_registers_.ContainsCoreRegister(reg)) { |
| 652 | __ popl(reg); |
| 653 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); |
| 654 | __ cfi().Restore(DWARFReg(reg)); |
| 655 | } |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 656 | } |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 657 | } |
David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 658 | __ ret(); |
| 659 | __ cfi().RestoreState(); |
| 660 | __ cfi().DefCFAOffset(GetFrameSize()); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 663 | void CodeGeneratorX86::Bind(HBasicBlock* block) { |
| 664 | __ Bind(GetLabelOf(block)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 667 | Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const { |
| 668 | switch (load->GetType()) { |
| 669 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 670 | case Primitive::kPrimDouble: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 671 | return Location::DoubleStackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 672 | |
| 673 | case Primitive::kPrimInt: |
| 674 | case Primitive::kPrimNot: |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 675 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 676 | return Location::StackSlot(GetStackSlot(load->GetLocal())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 677 | |
| 678 | case Primitive::kPrimBoolean: |
| 679 | case Primitive::kPrimByte: |
| 680 | case Primitive::kPrimChar: |
| 681 | case Primitive::kPrimShort: |
| 682 | case Primitive::kPrimVoid: |
| 683 | LOG(FATAL) << "Unexpected type " << load->GetType(); |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 684 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | LOG(FATAL) << "Unreachable"; |
Andreas Gampe | 65b798e | 2015-04-06 09:35:22 -0700 | [diff] [blame] | 688 | UNREACHABLE(); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 691 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(Primitive::Type type) const { |
| 692 | switch (type) { |
| 693 | case Primitive::kPrimBoolean: |
| 694 | case Primitive::kPrimByte: |
| 695 | case Primitive::kPrimChar: |
| 696 | case Primitive::kPrimShort: |
| 697 | case Primitive::kPrimInt: |
| 698 | case Primitive::kPrimNot: |
| 699 | return Location::RegisterLocation(EAX); |
| 700 | |
| 701 | case Primitive::kPrimLong: |
| 702 | return Location::RegisterPairLocation(EAX, EDX); |
| 703 | |
| 704 | case Primitive::kPrimVoid: |
| 705 | return Location::NoLocation(); |
| 706 | |
| 707 | case Primitive::kPrimDouble: |
| 708 | case Primitive::kPrimFloat: |
| 709 | return Location::FpuRegisterLocation(XMM0); |
| 710 | } |
Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 711 | |
| 712 | UNREACHABLE(); |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { |
| 716 | return Location::RegisterLocation(kMethodRegisterArgument); |
| 717 | } |
| 718 | |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 719 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(Primitive::Type type) { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 720 | switch (type) { |
| 721 | case Primitive::kPrimBoolean: |
| 722 | case Primitive::kPrimByte: |
| 723 | case Primitive::kPrimChar: |
| 724 | case Primitive::kPrimShort: |
| 725 | case Primitive::kPrimInt: |
| 726 | case Primitive::kPrimNot: { |
| 727 | uint32_t index = gp_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 728 | stack_index_++; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 729 | if (index < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 730 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 731 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 732 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 733 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 734 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 735 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 736 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 737 | uint32_t index = gp_index_; |
| 738 | gp_index_ += 2; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 739 | stack_index_ += 2; |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 740 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 741 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( |
| 742 | calling_convention.GetRegisterPairAt(index)); |
| 743 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 744 | } else { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 745 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | case Primitive::kPrimFloat: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 750 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 751 | stack_index_++; |
| 752 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 753 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 754 | } else { |
| 755 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | case Primitive::kPrimDouble: { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 760 | uint32_t index = float_index_++; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 761 | stack_index_ += 2; |
| 762 | if (index < calling_convention.GetNumberOfFpuRegisters()) { |
| 763 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); |
| 764 | } else { |
| 765 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 769 | case Primitive::kPrimVoid: |
| 770 | LOG(FATAL) << "Unexpected parameter type " << type; |
| 771 | break; |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 772 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 773 | return Location(); |
| 774 | } |
Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 775 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 776 | void CodeGeneratorX86::Move32(Location destination, Location source) { |
| 777 | if (source.Equals(destination)) { |
| 778 | return; |
| 779 | } |
| 780 | if (destination.IsRegister()) { |
| 781 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 782 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 783 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 784 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 785 | } else { |
| 786 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 787 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 788 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 789 | } else if (destination.IsFpuRegister()) { |
| 790 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 791 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 792 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 793 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 794 | } else { |
| 795 | DCHECK(source.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 796 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 797 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 798 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 799 | DCHECK(destination.IsStackSlot()) << destination; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 800 | if (source.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 801 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 802 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 803 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 804 | } else if (source.IsConstant()) { |
| 805 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 806 | int32_t value = GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 807 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 808 | } else { |
| 809 | DCHECK(source.IsStackSlot()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 810 | __ pushl(Address(ESP, source.GetStackIndex())); |
| 811 | __ popl(Address(ESP, destination.GetStackIndex())); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 812 | } |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | void CodeGeneratorX86::Move64(Location destination, Location source) { |
| 817 | if (source.Equals(destination)) { |
| 818 | return; |
| 819 | } |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 820 | if (destination.IsRegisterPair()) { |
| 821 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 822 | EmitParallelMoves( |
| 823 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), |
| 824 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 825 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 826 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 827 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), |
| 828 | Primitive::kPrimInt); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 829 | } else if (source.IsFpuRegister()) { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 830 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); |
| 831 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); |
| 832 | __ psrlq(src_reg, Immediate(32)); |
| 833 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 834 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 835 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 836 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 837 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 838 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 839 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 840 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 841 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 842 | if (source.IsFpuRegister()) { |
| 843 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 844 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 845 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 846 | } else if (source.IsRegisterPair()) { |
| 847 | size_t elem_size = Primitive::ComponentSize(Primitive::kPrimInt); |
| 848 | // Create stack space for 2 elements. |
| 849 | __ subl(ESP, Immediate(2 * elem_size)); |
| 850 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); |
| 851 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); |
| 852 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 853 | // And remove the temporary stack space we allocated. |
| 854 | __ addl(ESP, Immediate(2 * elem_size)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 855 | } else { |
| 856 | LOG(FATAL) << "Unimplemented"; |
| 857 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 858 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 859 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 860 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 861 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 862 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 863 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 864 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 865 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 866 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 867 | } else if (source.IsConstant()) { |
| 868 | HConstant* constant = source.GetConstant(); |
| 869 | int64_t value; |
| 870 | if (constant->IsLongConstant()) { |
| 871 | value = constant->AsLongConstant()->GetValue(); |
| 872 | } else { |
| 873 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 874 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 875 | } |
| 876 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 877 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 878 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 879 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 880 | EmitParallelMoves( |
| 881 | Location::StackSlot(source.GetStackIndex()), |
| 882 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 883 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 884 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 885 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 886 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | } |
| 890 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 891 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 892 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 893 | if (instruction->IsCurrentMethod()) { |
| 894 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 895 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 896 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 897 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 898 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 899 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 900 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 901 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 902 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 903 | } else if (location.IsStackSlot()) { |
| 904 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 905 | } else { |
| 906 | DCHECK(location.IsConstant()); |
| 907 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 908 | } |
| 909 | } else if (const_to_move->IsLongConstant()) { |
| 910 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 911 | if (location.IsRegisterPair()) { |
| 912 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 913 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 914 | } else if (location.IsDoubleStackSlot()) { |
| 915 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 916 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 917 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 918 | } else { |
| 919 | DCHECK(location.IsConstant()); |
| 920 | DCHECK_EQ(location.GetConstant(), instruction); |
| 921 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 922 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 923 | } else if (instruction->IsTemporary()) { |
| 924 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 925 | if (temp_location.IsStackSlot()) { |
| 926 | Move32(location, temp_location); |
| 927 | } else { |
| 928 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 929 | Move64(location, temp_location); |
| 930 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 931 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 932 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 933 | switch (instruction->GetType()) { |
| 934 | case Primitive::kPrimBoolean: |
| 935 | case Primitive::kPrimByte: |
| 936 | case Primitive::kPrimChar: |
| 937 | case Primitive::kPrimShort: |
| 938 | case Primitive::kPrimInt: |
| 939 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 940 | case Primitive::kPrimFloat: |
| 941 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 942 | break; |
| 943 | |
| 944 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 945 | case Primitive::kPrimDouble: |
| 946 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 947 | break; |
| 948 | |
| 949 | default: |
| 950 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 951 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 952 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 953 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 954 | switch (instruction->GetType()) { |
| 955 | case Primitive::kPrimBoolean: |
| 956 | case Primitive::kPrimByte: |
| 957 | case Primitive::kPrimChar: |
| 958 | case Primitive::kPrimShort: |
| 959 | case Primitive::kPrimInt: |
| 960 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 961 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 962 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 963 | break; |
| 964 | |
| 965 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 966 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 967 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 968 | break; |
| 969 | |
| 970 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 971 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 972 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 976 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 977 | DCHECK(location.IsRegister()); |
| 978 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 979 | } |
| 980 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 981 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, Primitive::Type dst_type) { |
| 982 | if (Primitive::Is64BitType(dst_type)) { |
| 983 | Move64(dst, src); |
| 984 | } else { |
| 985 | Move32(dst, src); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { |
| 990 | if (location.IsRegister()) { |
| 991 | locations->AddTemp(location); |
| 992 | } else if (location.IsRegisterPair()) { |
| 993 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); |
| 994 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); |
| 995 | } else { |
| 996 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; |
| 997 | } |
| 998 | } |
| 999 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1000 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1001 | DCHECK(!successor->IsExitBlock()); |
| 1002 | |
| 1003 | HBasicBlock* block = got->GetBlock(); |
| 1004 | HInstruction* previous = got->GetPrevious(); |
| 1005 | |
| 1006 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1007 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1008 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 1009 | return; |
| 1010 | } |
| 1011 | |
| 1012 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 1013 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 1014 | } |
| 1015 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1016 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1020 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 1021 | got->SetLocations(nullptr); |
| 1022 | } |
| 1023 | |
| 1024 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 1025 | HandleGoto(got, got->GetSuccessor()); |
| 1026 | } |
| 1027 | |
| 1028 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1029 | try_boundary->SetLocations(nullptr); |
| 1030 | } |
| 1031 | |
| 1032 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1033 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1034 | if (!successor->IsExitBlock()) { |
| 1035 | HandleGoto(try_boundary, successor); |
| 1036 | } |
| 1037 | } |
| 1038 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1039 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1040 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1043 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1044 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1047 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 1048 | Label* true_label, |
| 1049 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1050 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1051 | __ j(kUnordered, true_label); |
| 1052 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1053 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1054 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1055 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 1059 | Label* true_label, |
| 1060 | Label* false_label) { |
| 1061 | LocationSummary* locations = cond->GetLocations(); |
| 1062 | Location left = locations->InAt(0); |
| 1063 | Location right = locations->InAt(1); |
| 1064 | IfCondition if_cond = cond->GetCondition(); |
| 1065 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1066 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1067 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1068 | IfCondition true_high_cond = if_cond; |
| 1069 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1070 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1071 | |
| 1072 | // Set the conditions for the test, remembering that == needs to be |
| 1073 | // decided using the low words. |
| 1074 | switch (if_cond) { |
| 1075 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1076 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1077 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1078 | break; |
| 1079 | case kCondLT: |
| 1080 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1081 | break; |
| 1082 | case kCondLE: |
| 1083 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1084 | break; |
| 1085 | case kCondGT: |
| 1086 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1087 | break; |
| 1088 | case kCondGE: |
| 1089 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1090 | break; |
| 1091 | } |
| 1092 | |
| 1093 | if (right.IsConstant()) { |
| 1094 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1095 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1096 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1097 | |
| 1098 | if (val_high == 0) { |
| 1099 | __ testl(left_high, left_high); |
| 1100 | } else { |
| 1101 | __ cmpl(left_high, Immediate(val_high)); |
| 1102 | } |
| 1103 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1104 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1105 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1106 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1107 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1108 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1109 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1110 | } |
| 1111 | // Must be equal high, so compare the lows. |
| 1112 | if (val_low == 0) { |
| 1113 | __ testl(left_low, left_low); |
| 1114 | } else { |
| 1115 | __ cmpl(left_low, Immediate(val_low)); |
| 1116 | } |
| 1117 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1118 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1119 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1120 | |
| 1121 | __ cmpl(left_high, right_high); |
| 1122 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1123 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1124 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1125 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1126 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1127 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1128 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1129 | } |
| 1130 | // Must be equal high, so compare the lows. |
| 1131 | __ cmpl(left_low, right_low); |
| 1132 | } |
| 1133 | // The last comparison might be unsigned. |
| 1134 | __ j(final_condition, true_label); |
| 1135 | } |
| 1136 | |
| 1137 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1138 | HCondition* condition, |
| 1139 | Label* true_target, |
| 1140 | Label* false_target, |
| 1141 | Label* always_true_target) { |
| 1142 | LocationSummary* locations = condition->GetLocations(); |
| 1143 | Location left = locations->InAt(0); |
| 1144 | Location right = locations->InAt(1); |
| 1145 | |
| 1146 | // We don't want true_target as a nullptr. |
| 1147 | if (true_target == nullptr) { |
| 1148 | true_target = always_true_target; |
| 1149 | } |
| 1150 | bool falls_through = (false_target == nullptr); |
| 1151 | |
| 1152 | // FP compares don't like null false_targets. |
| 1153 | if (false_target == nullptr) { |
| 1154 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1155 | } |
| 1156 | |
| 1157 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1158 | switch (type) { |
| 1159 | case Primitive::kPrimLong: |
| 1160 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1161 | break; |
| 1162 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1163 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1164 | GenerateFPJumps(condition, true_target, false_target); |
| 1165 | break; |
| 1166 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1167 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1168 | GenerateFPJumps(condition, true_target, false_target); |
| 1169 | break; |
| 1170 | default: |
| 1171 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1172 | } |
| 1173 | |
| 1174 | if (!falls_through) { |
| 1175 | __ jmp(false_target); |
| 1176 | } |
| 1177 | } |
| 1178 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1179 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| 1180 | Label* true_target, |
| 1181 | Label* false_target, |
| 1182 | Label* always_true_target) { |
| 1183 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1184 | if (cond->IsIntConstant()) { |
| 1185 | // Constant condition, statically compared against 1. |
| 1186 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1187 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1188 | if (always_true_target != nullptr) { |
| 1189 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1190 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1191 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1192 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1193 | DCHECK_EQ(cond_value, 0); |
| 1194 | } |
| 1195 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1196 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1197 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1198 | // Moves do not affect the eflags register, so if the condition is |
| 1199 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1200 | // again. We can't use the eflags on long/FP conditions if they are |
| 1201 | // materialized due to the complex branching. |
| 1202 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1203 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1204 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1205 | && (type != Primitive::kPrimLong && !Primitive::IsFloatingPointType(type)); |
| 1206 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1207 | if (!eflags_set) { |
| 1208 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1209 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1210 | if (lhs.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1211 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1212 | } else { |
| 1213 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1214 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1215 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1216 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1217 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1218 | } |
| 1219 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1220 | // Condition has not been materialized, use its inputs as the |
| 1221 | // comparison and its condition as the branch condition. |
| 1222 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1223 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1224 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1225 | // Generate the comparison directly. |
| 1226 | GenerateCompareTestAndBranch(instruction->AsIf(), |
| 1227 | cond->AsCondition(), |
| 1228 | true_target, |
| 1229 | false_target, |
| 1230 | always_true_target); |
| 1231 | return; |
| 1232 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1233 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1234 | Location lhs = cond->GetLocations()->InAt(0); |
| 1235 | Location rhs = cond->GetLocations()->InAt(1); |
| 1236 | // LHS is guaranteed to be in a register (see |
| 1237 | // LocationsBuilderX86::VisitCondition). |
| 1238 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1239 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1240 | } else if (rhs.IsConstant()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame] | 1241 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1242 | if (constant == 0) { |
| 1243 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1244 | } else { |
| 1245 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1246 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1247 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1248 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1249 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1250 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1251 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1252 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1253 | if (false_target != nullptr) { |
| 1254 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1255 | } |
| 1256 | } |
| 1257 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1258 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| 1259 | LocationSummary* locations = |
| 1260 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1261 | HInstruction* cond = if_instr->InputAt(0); |
| 1262 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1263 | locations->SetInAt(0, Location::Any()); |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| 1268 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1269 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1270 | Label* always_true_target = true_target; |
| 1271 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1272 | if_instr->IfTrueSuccessor())) { |
| 1273 | always_true_target = nullptr; |
| 1274 | } |
| 1275 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1276 | if_instr->IfFalseSuccessor())) { |
| 1277 | false_target = nullptr; |
| 1278 | } |
| 1279 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1280 | } |
| 1281 | |
| 1282 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1283 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1284 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1285 | HInstruction* cond = deoptimize->InputAt(0); |
| 1286 | DCHECK(cond->IsCondition()); |
| 1287 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1288 | locations->SetInAt(0, Location::Any()); |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1293 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1294 | DeoptimizationSlowPathX86(deoptimize); |
| 1295 | codegen_->AddSlowPath(slow_path); |
| 1296 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1297 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1298 | } |
| 1299 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1300 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1301 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1304 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1305 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1308 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1309 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1312 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1313 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1314 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1317 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1318 | LocationSummary* locations = |
| 1319 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1320 | switch (store->InputAt(1)->GetType()) { |
| 1321 | case Primitive::kPrimBoolean: |
| 1322 | case Primitive::kPrimByte: |
| 1323 | case Primitive::kPrimChar: |
| 1324 | case Primitive::kPrimShort: |
| 1325 | case Primitive::kPrimInt: |
| 1326 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1327 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1328 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1329 | break; |
| 1330 | |
| 1331 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1332 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1333 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1334 | break; |
| 1335 | |
| 1336 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1337 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1338 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1341 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1342 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1345 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1346 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1347 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1348 | // Handle the long/FP comparisons made in instruction simplification. |
| 1349 | switch (cond->InputAt(0)->GetType()) { |
| 1350 | case Primitive::kPrimLong: { |
| 1351 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1352 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1353 | if (cond->NeedsMaterialization()) { |
| 1354 | locations->SetOut(Location::RequiresRegister()); |
| 1355 | } |
| 1356 | break; |
| 1357 | } |
| 1358 | case Primitive::kPrimFloat: |
| 1359 | case Primitive::kPrimDouble: { |
| 1360 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1361 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1362 | if (cond->NeedsMaterialization()) { |
| 1363 | locations->SetOut(Location::RequiresRegister()); |
| 1364 | } |
| 1365 | break; |
| 1366 | } |
| 1367 | default: |
| 1368 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1369 | locations->SetInAt(1, Location::Any()); |
| 1370 | if (cond->NeedsMaterialization()) { |
| 1371 | // We need a byte register. |
| 1372 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1373 | } |
| 1374 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1375 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1376 | } |
| 1377 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1378 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1379 | if (!cond->NeedsMaterialization()) { |
| 1380 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1381 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1382 | |
| 1383 | LocationSummary* locations = cond->GetLocations(); |
| 1384 | Location lhs = locations->InAt(0); |
| 1385 | Location rhs = locations->InAt(1); |
| 1386 | Register reg = locations->Out().AsRegister<Register>(); |
| 1387 | Label true_label, false_label; |
| 1388 | |
| 1389 | switch (cond->InputAt(0)->GetType()) { |
| 1390 | default: { |
| 1391 | // Integer case. |
| 1392 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1393 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1394 | __ xorl(reg, reg); |
| 1395 | |
| 1396 | if (rhs.IsRegister()) { |
| 1397 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1398 | } else if (rhs.IsConstant()) { |
| 1399 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1400 | if (constant == 0) { |
| 1401 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1402 | } else { |
| 1403 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1404 | } |
| 1405 | } else { |
| 1406 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1407 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1408 | __ setb(X86SignedCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1409 | return; |
| 1410 | } |
| 1411 | case Primitive::kPrimLong: |
| 1412 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1413 | break; |
| 1414 | case Primitive::kPrimFloat: |
| 1415 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1416 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1417 | break; |
| 1418 | case Primitive::kPrimDouble: |
| 1419 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1420 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1421 | break; |
| 1422 | } |
| 1423 | |
| 1424 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1425 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1426 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1427 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1428 | __ Bind(&false_label); |
| 1429 | __ xorl(reg, reg); |
| 1430 | __ jmp(&done_label); |
| 1431 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1432 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1433 | __ Bind(&true_label); |
| 1434 | __ movl(reg, Immediate(1)); |
| 1435 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1439 | VisitCondition(comp); |
| 1440 | } |
| 1441 | |
| 1442 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1443 | VisitCondition(comp); |
| 1444 | } |
| 1445 | |
| 1446 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1447 | VisitCondition(comp); |
| 1448 | } |
| 1449 | |
| 1450 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1451 | VisitCondition(comp); |
| 1452 | } |
| 1453 | |
| 1454 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1455 | VisitCondition(comp); |
| 1456 | } |
| 1457 | |
| 1458 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1459 | VisitCondition(comp); |
| 1460 | } |
| 1461 | |
| 1462 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1463 | VisitCondition(comp); |
| 1464 | } |
| 1465 | |
| 1466 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1467 | VisitCondition(comp); |
| 1468 | } |
| 1469 | |
| 1470 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1471 | VisitCondition(comp); |
| 1472 | } |
| 1473 | |
| 1474 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1475 | VisitCondition(comp); |
| 1476 | } |
| 1477 | |
| 1478 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1479 | VisitCondition(comp); |
| 1480 | } |
| 1481 | |
| 1482 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1483 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1487 | LocationSummary* locations = |
| 1488 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1489 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1492 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1493 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1494 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1497 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1498 | LocationSummary* locations = |
| 1499 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1500 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1501 | } |
| 1502 | |
| 1503 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant) { |
| 1504 | // Will be generated at use site. |
| 1505 | UNUSED(constant); |
| 1506 | } |
| 1507 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1508 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1509 | LocationSummary* locations = |
| 1510 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1511 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 1515 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1516 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1517 | } |
| 1518 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1519 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1520 | LocationSummary* locations = |
| 1521 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1522 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1523 | } |
| 1524 | |
| 1525 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1526 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1527 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1531 | LocationSummary* locations = |
| 1532 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1533 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1534 | } |
| 1535 | |
| 1536 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1537 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1538 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1539 | } |
| 1540 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1541 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1542 | memory_barrier->SetLocations(nullptr); |
| 1543 | } |
| 1544 | |
| 1545 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1546 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1547 | } |
| 1548 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1549 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1550 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1553 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1554 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1555 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1558 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1559 | LocationSummary* locations = |
| 1560 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1561 | switch (ret->InputAt(0)->GetType()) { |
| 1562 | case Primitive::kPrimBoolean: |
| 1563 | case Primitive::kPrimByte: |
| 1564 | case Primitive::kPrimChar: |
| 1565 | case Primitive::kPrimShort: |
| 1566 | case Primitive::kPrimInt: |
| 1567 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1568 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1569 | break; |
| 1570 | |
| 1571 | case Primitive::kPrimLong: |
| 1572 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1573 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1574 | break; |
| 1575 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1576 | case Primitive::kPrimFloat: |
| 1577 | case Primitive::kPrimDouble: |
| 1578 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1579 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1580 | break; |
| 1581 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1582 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1583 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1584 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1587 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1588 | if (kIsDebugBuild) { |
| 1589 | switch (ret->InputAt(0)->GetType()) { |
| 1590 | case Primitive::kPrimBoolean: |
| 1591 | case Primitive::kPrimByte: |
| 1592 | case Primitive::kPrimChar: |
| 1593 | case Primitive::kPrimShort: |
| 1594 | case Primitive::kPrimInt: |
| 1595 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1596 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1597 | break; |
| 1598 | |
| 1599 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1600 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1601 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1602 | break; |
| 1603 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1604 | case Primitive::kPrimFloat: |
| 1605 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1606 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1607 | break; |
| 1608 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1609 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1610 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1611 | } |
| 1612 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1613 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1616 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1617 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1618 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1619 | // the method_idx. |
| 1620 | HandleInvoke(invoke); |
| 1621 | } |
| 1622 | |
| 1623 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1624 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1625 | } |
| 1626 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1627 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1628 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1629 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1630 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1631 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1632 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1633 | if (intrinsic.TryDispatch(invoke)) { |
| 1634 | return; |
| 1635 | } |
| 1636 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1637 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1638 | |
| 1639 | if (codegen_->IsBaseline()) { |
| 1640 | // Baseline does not have enough registers if the current method also |
| 1641 | // needs a register. We therefore do not require a register for it, and let |
| 1642 | // the code generation of the invoke handle it. |
| 1643 | LocationSummary* locations = invoke->GetLocations(); |
| 1644 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 1645 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 1646 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 1647 | } |
| 1648 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1649 | } |
| 1650 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1651 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1652 | if (invoke->GetLocations()->Intrinsified()) { |
| 1653 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1654 | intrinsic.Dispatch(invoke); |
| 1655 | return true; |
| 1656 | } |
| 1657 | return false; |
| 1658 | } |
| 1659 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1660 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1661 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1662 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1663 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1664 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1665 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1666 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1667 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1668 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1669 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1670 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1671 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1672 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1676 | HandleInvoke(invoke); |
| 1677 | } |
| 1678 | |
| 1679 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1680 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1681 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1684 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1685 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1686 | return; |
| 1687 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1688 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1689 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1690 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1691 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1694 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1695 | HandleInvoke(invoke); |
| 1696 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1697 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1701 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1702 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1703 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1704 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1705 | LocationSummary* locations = invoke->GetLocations(); |
| 1706 | Location receiver = locations->InAt(0); |
| 1707 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1708 | |
| 1709 | // Set the hidden argument. |
| 1710 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1711 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1712 | |
| 1713 | // temp = object->GetClass(); |
| 1714 | if (receiver.IsStackSlot()) { |
| 1715 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1716 | __ movl(temp, Address(temp, class_offset)); |
| 1717 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1718 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1719 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1720 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1721 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1722 | // temp = temp->GetImtEntryAt(method_offset); |
| 1723 | __ movl(temp, Address(temp, method_offset)); |
| 1724 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1725 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1726 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1727 | |
| 1728 | DCHECK(!codegen_->IsLeafMethod()); |
| 1729 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1730 | } |
| 1731 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1732 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1733 | LocationSummary* locations = |
| 1734 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1735 | switch (neg->GetResultType()) { |
| 1736 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1737 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1738 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1739 | locations->SetOut(Location::SameAsFirstInput()); |
| 1740 | break; |
| 1741 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1742 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1743 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1744 | locations->SetOut(Location::SameAsFirstInput()); |
| 1745 | locations->AddTemp(Location::RequiresRegister()); |
| 1746 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1747 | break; |
| 1748 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1749 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1750 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1751 | locations->SetOut(Location::SameAsFirstInput()); |
| 1752 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1753 | break; |
| 1754 | |
| 1755 | default: |
| 1756 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1761 | LocationSummary* locations = neg->GetLocations(); |
| 1762 | Location out = locations->Out(); |
| 1763 | Location in = locations->InAt(0); |
| 1764 | switch (neg->GetResultType()) { |
| 1765 | case Primitive::kPrimInt: |
| 1766 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1767 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1768 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1769 | break; |
| 1770 | |
| 1771 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1772 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1773 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1774 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1775 | // Negation is similar to subtraction from zero. The least |
| 1776 | // significant byte triggers a borrow when it is different from |
| 1777 | // zero; to take it into account, add 1 to the most significant |
| 1778 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1779 | // operation. |
| 1780 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1781 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1782 | break; |
| 1783 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1784 | case Primitive::kPrimFloat: { |
| 1785 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1786 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1787 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1788 | // Implement float negation with an exclusive or with value |
| 1789 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1790 | // single-precision floating-point number). |
| 1791 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1792 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1793 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1794 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1795 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1796 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1797 | case Primitive::kPrimDouble: { |
| 1798 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1799 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1800 | // Implement double negation with an exclusive or with value |
| 1801 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1802 | // a double-precision floating-point number). |
| 1803 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1804 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1805 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1806 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1807 | |
| 1808 | default: |
| 1809 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1810 | } |
| 1811 | } |
| 1812 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1813 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1814 | Primitive::Type result_type = conversion->GetResultType(); |
| 1815 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1816 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1817 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1818 | // The float-to-long and double-to-long type conversions rely on a |
| 1819 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1820 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1821 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1822 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1823 | ? LocationSummary::kCall |
| 1824 | : LocationSummary::kNoCall; |
| 1825 | LocationSummary* locations = |
| 1826 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1827 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1828 | // The Java language does not allow treating boolean as an integral type but |
| 1829 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1830 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1831 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1832 | case Primitive::kPrimByte: |
| 1833 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1834 | case Primitive::kPrimBoolean: |
| 1835 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1836 | case Primitive::kPrimShort: |
| 1837 | case Primitive::kPrimInt: |
| 1838 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1839 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1840 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1841 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1842 | // the validation of the linear scan implementation |
| 1843 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1844 | break; |
| 1845 | |
| 1846 | default: |
| 1847 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1848 | << " to " << result_type; |
| 1849 | } |
| 1850 | break; |
| 1851 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1852 | case Primitive::kPrimShort: |
| 1853 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1854 | case Primitive::kPrimBoolean: |
| 1855 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1856 | case Primitive::kPrimByte: |
| 1857 | case Primitive::kPrimInt: |
| 1858 | case Primitive::kPrimChar: |
| 1859 | // Processing a Dex `int-to-short' instruction. |
| 1860 | locations->SetInAt(0, Location::Any()); |
| 1861 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1862 | break; |
| 1863 | |
| 1864 | default: |
| 1865 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1866 | << " to " << result_type; |
| 1867 | } |
| 1868 | break; |
| 1869 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1870 | case Primitive::kPrimInt: |
| 1871 | switch (input_type) { |
| 1872 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1873 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1874 | locations->SetInAt(0, Location::Any()); |
| 1875 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1876 | break; |
| 1877 | |
| 1878 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1879 | // Processing a Dex `float-to-int' instruction. |
| 1880 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1881 | locations->SetOut(Location::RequiresRegister()); |
| 1882 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1883 | break; |
| 1884 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1885 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1886 | // Processing a Dex `double-to-int' instruction. |
| 1887 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1888 | locations->SetOut(Location::RequiresRegister()); |
| 1889 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1890 | break; |
| 1891 | |
| 1892 | default: |
| 1893 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1894 | << " to " << result_type; |
| 1895 | } |
| 1896 | break; |
| 1897 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1898 | case Primitive::kPrimLong: |
| 1899 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1900 | case Primitive::kPrimBoolean: |
| 1901 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1902 | case Primitive::kPrimByte: |
| 1903 | case Primitive::kPrimShort: |
| 1904 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1905 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1906 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1907 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1908 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1909 | break; |
| 1910 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1911 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1912 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1913 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1914 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1915 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1916 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1917 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1918 | // The runtime helper puts the result in EAX, EDX. |
| 1919 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1920 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1921 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1922 | |
| 1923 | default: |
| 1924 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1925 | << " to " << result_type; |
| 1926 | } |
| 1927 | break; |
| 1928 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1929 | case Primitive::kPrimChar: |
| 1930 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1931 | case Primitive::kPrimBoolean: |
| 1932 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1933 | case Primitive::kPrimByte: |
| 1934 | case Primitive::kPrimShort: |
| 1935 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1936 | // Processing a Dex `int-to-char' instruction. |
| 1937 | locations->SetInAt(0, Location::Any()); |
| 1938 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1939 | break; |
| 1940 | |
| 1941 | default: |
| 1942 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1943 | << " to " << result_type; |
| 1944 | } |
| 1945 | break; |
| 1946 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1947 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1948 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1949 | case Primitive::kPrimBoolean: |
| 1950 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1951 | case Primitive::kPrimByte: |
| 1952 | case Primitive::kPrimShort: |
| 1953 | case Primitive::kPrimInt: |
| 1954 | case Primitive::kPrimChar: |
| 1955 | // Processing a Dex `int-to-float' instruction. |
| 1956 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1957 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1958 | break; |
| 1959 | |
| 1960 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1961 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1962 | locations->SetInAt(0, Location::Any()); |
| 1963 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1964 | break; |
| 1965 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1966 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1967 | // Processing a Dex `double-to-float' instruction. |
| 1968 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1969 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1970 | break; |
| 1971 | |
| 1972 | default: |
| 1973 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1974 | << " to " << result_type; |
| 1975 | }; |
| 1976 | break; |
| 1977 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1978 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1979 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1980 | case Primitive::kPrimBoolean: |
| 1981 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1982 | case Primitive::kPrimByte: |
| 1983 | case Primitive::kPrimShort: |
| 1984 | case Primitive::kPrimInt: |
| 1985 | case Primitive::kPrimChar: |
| 1986 | // Processing a Dex `int-to-double' instruction. |
| 1987 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1988 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1989 | break; |
| 1990 | |
| 1991 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1992 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1993 | locations->SetInAt(0, Location::Any()); |
| 1994 | locations->SetOut(Location::Any()); |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1995 | break; |
| 1996 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1997 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1998 | // Processing a Dex `float-to-double' instruction. |
| 1999 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2000 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2001 | break; |
| 2002 | |
| 2003 | default: |
| 2004 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2005 | << " to " << result_type; |
| 2006 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2007 | break; |
| 2008 | |
| 2009 | default: |
| 2010 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2011 | << " to " << result_type; |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 2016 | LocationSummary* locations = conversion->GetLocations(); |
| 2017 | Location out = locations->Out(); |
| 2018 | Location in = locations->InAt(0); |
| 2019 | Primitive::Type result_type = conversion->GetResultType(); |
| 2020 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 2021 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2022 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2023 | case Primitive::kPrimByte: |
| 2024 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2025 | case Primitive::kPrimBoolean: |
| 2026 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2027 | case Primitive::kPrimShort: |
| 2028 | case Primitive::kPrimInt: |
| 2029 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2030 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2031 | if (in.IsRegister()) { |
| 2032 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2033 | } else { |
| 2034 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2035 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2036 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2037 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2038 | break; |
| 2039 | |
| 2040 | default: |
| 2041 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2042 | << " to " << result_type; |
| 2043 | } |
| 2044 | break; |
| 2045 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2046 | case Primitive::kPrimShort: |
| 2047 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2048 | case Primitive::kPrimBoolean: |
| 2049 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2050 | case Primitive::kPrimByte: |
| 2051 | case Primitive::kPrimInt: |
| 2052 | case Primitive::kPrimChar: |
| 2053 | // Processing a Dex `int-to-short' instruction. |
| 2054 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2055 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2056 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2057 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2058 | } else { |
| 2059 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2060 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2061 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2062 | } |
| 2063 | break; |
| 2064 | |
| 2065 | default: |
| 2066 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2067 | << " to " << result_type; |
| 2068 | } |
| 2069 | break; |
| 2070 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2071 | case Primitive::kPrimInt: |
| 2072 | switch (input_type) { |
| 2073 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2074 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2075 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2076 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2077 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2078 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2079 | } else { |
| 2080 | DCHECK(in.IsConstant()); |
| 2081 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2082 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2083 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2084 | } |
| 2085 | break; |
| 2086 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2087 | case Primitive::kPrimFloat: { |
| 2088 | // Processing a Dex `float-to-int' instruction. |
| 2089 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2090 | Register output = out.AsRegister<Register>(); |
| 2091 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2092 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2093 | |
| 2094 | __ movl(output, Immediate(kPrimIntMax)); |
| 2095 | // temp = int-to-float(output) |
| 2096 | __ cvtsi2ss(temp, output); |
| 2097 | // if input >= temp goto done |
| 2098 | __ comiss(input, temp); |
| 2099 | __ j(kAboveEqual, &done); |
| 2100 | // if input == NaN goto nan |
| 2101 | __ j(kUnordered, &nan); |
| 2102 | // output = float-to-int-truncate(input) |
| 2103 | __ cvttss2si(output, input); |
| 2104 | __ jmp(&done); |
| 2105 | __ Bind(&nan); |
| 2106 | // output = 0 |
| 2107 | __ xorl(output, output); |
| 2108 | __ Bind(&done); |
| 2109 | break; |
| 2110 | } |
| 2111 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2112 | case Primitive::kPrimDouble: { |
| 2113 | // Processing a Dex `double-to-int' instruction. |
| 2114 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2115 | Register output = out.AsRegister<Register>(); |
| 2116 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2117 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2118 | |
| 2119 | __ movl(output, Immediate(kPrimIntMax)); |
| 2120 | // temp = int-to-double(output) |
| 2121 | __ cvtsi2sd(temp, output); |
| 2122 | // if input >= temp goto done |
| 2123 | __ comisd(input, temp); |
| 2124 | __ j(kAboveEqual, &done); |
| 2125 | // if input == NaN goto nan |
| 2126 | __ j(kUnordered, &nan); |
| 2127 | // output = double-to-int-truncate(input) |
| 2128 | __ cvttsd2si(output, input); |
| 2129 | __ jmp(&done); |
| 2130 | __ Bind(&nan); |
| 2131 | // output = 0 |
| 2132 | __ xorl(output, output); |
| 2133 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2134 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2135 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2136 | |
| 2137 | default: |
| 2138 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2139 | << " to " << result_type; |
| 2140 | } |
| 2141 | break; |
| 2142 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2143 | case Primitive::kPrimLong: |
| 2144 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2145 | case Primitive::kPrimBoolean: |
| 2146 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2147 | case Primitive::kPrimByte: |
| 2148 | case Primitive::kPrimShort: |
| 2149 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2150 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2151 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2152 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2153 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2154 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2155 | __ cdq(); |
| 2156 | break; |
| 2157 | |
| 2158 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2159 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2160 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2161 | conversion, |
| 2162 | conversion->GetDexPc(), |
| 2163 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2164 | break; |
| 2165 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2166 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2167 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2168 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2169 | conversion, |
| 2170 | conversion->GetDexPc(), |
| 2171 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2172 | break; |
| 2173 | |
| 2174 | default: |
| 2175 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2176 | << " to " << result_type; |
| 2177 | } |
| 2178 | break; |
| 2179 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2180 | case Primitive::kPrimChar: |
| 2181 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2182 | case Primitive::kPrimBoolean: |
| 2183 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2184 | case Primitive::kPrimByte: |
| 2185 | case Primitive::kPrimShort: |
| 2186 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2187 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2188 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2189 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2190 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2191 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2192 | } else { |
| 2193 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2194 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2195 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2196 | } |
| 2197 | break; |
| 2198 | |
| 2199 | default: |
| 2200 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2201 | << " to " << result_type; |
| 2202 | } |
| 2203 | break; |
| 2204 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2205 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2206 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2207 | case Primitive::kPrimBoolean: |
| 2208 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2209 | case Primitive::kPrimByte: |
| 2210 | case Primitive::kPrimShort: |
| 2211 | case Primitive::kPrimInt: |
| 2212 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2213 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2214 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2215 | break; |
| 2216 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2217 | case Primitive::kPrimLong: { |
| 2218 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2219 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2220 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2221 | // Create stack space for the call to |
| 2222 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2223 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2224 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2225 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2226 | __ subl(ESP, Immediate(adjustment)); |
| 2227 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2228 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2229 | // Load the value to the FP stack, using temporaries if needed. |
| 2230 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2231 | |
| 2232 | if (out.IsStackSlot()) { |
| 2233 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2234 | } else { |
| 2235 | __ fstps(Address(ESP, 0)); |
| 2236 | Location stack_temp = Location::StackSlot(0); |
| 2237 | codegen_->Move32(out, stack_temp); |
| 2238 | } |
| 2239 | |
| 2240 | // Remove the temporary stack space we allocated. |
| 2241 | if (adjustment != 0) { |
| 2242 | __ addl(ESP, Immediate(adjustment)); |
| 2243 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2244 | break; |
| 2245 | } |
| 2246 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2247 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2248 | // Processing a Dex `double-to-float' instruction. |
| 2249 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2250 | break; |
| 2251 | |
| 2252 | default: |
| 2253 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2254 | << " to " << result_type; |
| 2255 | }; |
| 2256 | break; |
| 2257 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2258 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2259 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2260 | case Primitive::kPrimBoolean: |
| 2261 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2262 | case Primitive::kPrimByte: |
| 2263 | case Primitive::kPrimShort: |
| 2264 | case Primitive::kPrimInt: |
| 2265 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2266 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2267 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2268 | break; |
| 2269 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2270 | case Primitive::kPrimLong: { |
| 2271 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2272 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2273 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2274 | // Create stack space for the call to |
| 2275 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2276 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2277 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2278 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2279 | __ subl(ESP, Immediate(adjustment)); |
| 2280 | } |
| 2281 | |
| 2282 | // Load the value to the FP stack, using temporaries if needed. |
| 2283 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2284 | |
| 2285 | if (out.IsDoubleStackSlot()) { |
| 2286 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2287 | } else { |
| 2288 | __ fstpl(Address(ESP, 0)); |
| 2289 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2290 | codegen_->Move64(out, stack_temp); |
| 2291 | } |
| 2292 | |
| 2293 | // Remove the temporary stack space we allocated. |
| 2294 | if (adjustment != 0) { |
| 2295 | __ addl(ESP, Immediate(adjustment)); |
| 2296 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2297 | break; |
| 2298 | } |
| 2299 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2300 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2301 | // Processing a Dex `float-to-double' instruction. |
| 2302 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2303 | break; |
| 2304 | |
| 2305 | default: |
| 2306 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2307 | << " to " << result_type; |
| 2308 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2309 | break; |
| 2310 | |
| 2311 | default: |
| 2312 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2313 | << " to " << result_type; |
| 2314 | } |
| 2315 | } |
| 2316 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2317 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2318 | LocationSummary* locations = |
| 2319 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2320 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2321 | case Primitive::kPrimInt: { |
| 2322 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2323 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2324 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2325 | break; |
| 2326 | } |
| 2327 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2328 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2329 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2330 | locations->SetInAt(1, Location::Any()); |
| 2331 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2332 | break; |
| 2333 | } |
| 2334 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2335 | case Primitive::kPrimFloat: |
| 2336 | case Primitive::kPrimDouble: { |
| 2337 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2338 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2339 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2340 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2341 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2342 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2343 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2344 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2345 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2346 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2350 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2351 | Location first = locations->InAt(0); |
| 2352 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2353 | Location out = locations->Out(); |
| 2354 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2355 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2356 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2357 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2358 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2359 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2360 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2361 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2362 | } else { |
| 2363 | __ leal(out.AsRegister<Register>(), Address( |
| 2364 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2365 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2366 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2367 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2368 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2369 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2370 | } else { |
| 2371 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2372 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2373 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2374 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2375 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2376 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2377 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2381 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2382 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2383 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2384 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2385 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2386 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2387 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2388 | } else { |
| 2389 | DCHECK(second.IsConstant()) << second; |
| 2390 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2391 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2392 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2393 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2394 | break; |
| 2395 | } |
| 2396 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2397 | case Primitive::kPrimFloat: { |
| 2398 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2399 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2400 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2401 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2402 | DCHECK(!const_area->NeedsMaterialization()); |
| 2403 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2404 | codegen_->LiteralFloatAddress( |
| 2405 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2406 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2407 | } else { |
| 2408 | DCHECK(second.IsStackSlot()); |
| 2409 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2410 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2411 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | case Primitive::kPrimDouble: { |
| 2415 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2416 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2417 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2418 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2419 | DCHECK(!const_area->NeedsMaterialization()); |
| 2420 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2421 | codegen_->LiteralDoubleAddress( |
| 2422 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2423 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2424 | } else { |
| 2425 | DCHECK(second.IsDoubleStackSlot()); |
| 2426 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2427 | } |
| 2428 | break; |
| 2429 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2430 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2431 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2432 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2433 | } |
| 2434 | } |
| 2435 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2436 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2437 | LocationSummary* locations = |
| 2438 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2439 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2440 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2441 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2442 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2443 | locations->SetInAt(1, Location::Any()); |
| 2444 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2445 | break; |
| 2446 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2447 | case Primitive::kPrimFloat: |
| 2448 | case Primitive::kPrimDouble: { |
| 2449 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2450 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2451 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2452 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2453 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2454 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2455 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2456 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2457 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2461 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2462 | Location first = locations->InAt(0); |
| 2463 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2464 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2465 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2466 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2467 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2468 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2469 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2470 | __ subl(first.AsRegister<Register>(), |
| 2471 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2472 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2473 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2474 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2475 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2479 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2480 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2481 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2482 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2483 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2484 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2485 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2486 | } else { |
| 2487 | DCHECK(second.IsConstant()) << second; |
| 2488 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2489 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2490 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2491 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2492 | break; |
| 2493 | } |
| 2494 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2495 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2496 | if (second.IsFpuRegister()) { |
| 2497 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2498 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2499 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2500 | DCHECK(!const_area->NeedsMaterialization()); |
| 2501 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2502 | codegen_->LiteralFloatAddress( |
| 2503 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2504 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2505 | } else { |
| 2506 | DCHECK(second.IsStackSlot()); |
| 2507 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2508 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2509 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2513 | if (second.IsFpuRegister()) { |
| 2514 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2515 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2516 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2517 | DCHECK(!const_area->NeedsMaterialization()); |
| 2518 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2519 | codegen_->LiteralDoubleAddress( |
| 2520 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2521 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2522 | } else { |
| 2523 | DCHECK(second.IsDoubleStackSlot()); |
| 2524 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2525 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2526 | break; |
| 2527 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2528 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2529 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2530 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2531 | } |
| 2532 | } |
| 2533 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2534 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2535 | LocationSummary* locations = |
| 2536 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2537 | switch (mul->GetResultType()) { |
| 2538 | case Primitive::kPrimInt: |
| 2539 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2540 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2541 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2542 | // Can use 3 operand multiply. |
| 2543 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2544 | } else { |
| 2545 | locations->SetOut(Location::SameAsFirstInput()); |
| 2546 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2547 | break; |
| 2548 | case Primitive::kPrimLong: { |
| 2549 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2550 | locations->SetInAt(1, Location::Any()); |
| 2551 | locations->SetOut(Location::SameAsFirstInput()); |
| 2552 | // Needed for imul on 32bits with 64bits output. |
| 2553 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2554 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2555 | break; |
| 2556 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2557 | case Primitive::kPrimFloat: |
| 2558 | case Primitive::kPrimDouble: { |
| 2559 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2560 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2561 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2562 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2563 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2564 | |
| 2565 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2566 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2567 | } |
| 2568 | } |
| 2569 | |
| 2570 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2571 | LocationSummary* locations = mul->GetLocations(); |
| 2572 | Location first = locations->InAt(0); |
| 2573 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2574 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2575 | |
| 2576 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2577 | case Primitive::kPrimInt: |
| 2578 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2579 | // problems where the output may not be the same as the first operand. |
| 2580 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2581 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2582 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2583 | } else if (second.IsRegister()) { |
| 2584 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2585 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2586 | } else { |
| 2587 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2588 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2589 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2590 | } |
| 2591 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2592 | |
| 2593 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2594 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2595 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2596 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2597 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2598 | |
| 2599 | DCHECK_EQ(EAX, eax); |
| 2600 | DCHECK_EQ(EDX, edx); |
| 2601 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2602 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2603 | // output: in1 |
| 2604 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2605 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2606 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2607 | if (second.IsConstant()) { |
| 2608 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2609 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2610 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2611 | int32_t low_value = Low32Bits(value); |
| 2612 | int32_t high_value = High32Bits(value); |
| 2613 | Immediate low(low_value); |
| 2614 | Immediate high(high_value); |
| 2615 | |
| 2616 | __ movl(eax, high); |
| 2617 | // eax <- in1.lo * in2.hi |
| 2618 | __ imull(eax, in1_lo); |
| 2619 | // in1.hi <- in1.hi * in2.lo |
| 2620 | __ imull(in1_hi, low); |
| 2621 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2622 | __ addl(in1_hi, eax); |
| 2623 | // move in2_lo to eax to prepare for double precision |
| 2624 | __ movl(eax, low); |
| 2625 | // edx:eax <- in1.lo * in2.lo |
| 2626 | __ mull(in1_lo); |
| 2627 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2628 | __ addl(in1_hi, edx); |
| 2629 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2630 | __ movl(in1_lo, eax); |
| 2631 | } else if (second.IsRegisterPair()) { |
| 2632 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2633 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2634 | |
| 2635 | __ movl(eax, in2_hi); |
| 2636 | // eax <- in1.lo * in2.hi |
| 2637 | __ imull(eax, in1_lo); |
| 2638 | // in1.hi <- in1.hi * in2.lo |
| 2639 | __ imull(in1_hi, in2_lo); |
| 2640 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2641 | __ addl(in1_hi, eax); |
| 2642 | // move in1_lo to eax to prepare for double precision |
| 2643 | __ movl(eax, in1_lo); |
| 2644 | // edx:eax <- in1.lo * in2.lo |
| 2645 | __ mull(in2_lo); |
| 2646 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2647 | __ addl(in1_hi, edx); |
| 2648 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2649 | __ movl(in1_lo, eax); |
| 2650 | } else { |
| 2651 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2652 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2653 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2654 | |
| 2655 | __ movl(eax, in2_hi); |
| 2656 | // eax <- in1.lo * in2.hi |
| 2657 | __ imull(eax, in1_lo); |
| 2658 | // in1.hi <- in1.hi * in2.lo |
| 2659 | __ imull(in1_hi, in2_lo); |
| 2660 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2661 | __ addl(in1_hi, eax); |
| 2662 | // move in1_lo to eax to prepare for double precision |
| 2663 | __ movl(eax, in1_lo); |
| 2664 | // edx:eax <- in1.lo * in2.lo |
| 2665 | __ mull(in2_lo); |
| 2666 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2667 | __ addl(in1_hi, edx); |
| 2668 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2669 | __ movl(in1_lo, eax); |
| 2670 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2671 | |
| 2672 | break; |
| 2673 | } |
| 2674 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2675 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2676 | DCHECK(first.Equals(locations->Out())); |
| 2677 | if (second.IsFpuRegister()) { |
| 2678 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2679 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2680 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2681 | DCHECK(!const_area->NeedsMaterialization()); |
| 2682 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2683 | codegen_->LiteralFloatAddress( |
| 2684 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2685 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2686 | } else { |
| 2687 | DCHECK(second.IsStackSlot()); |
| 2688 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2689 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2690 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2694 | DCHECK(first.Equals(locations->Out())); |
| 2695 | if (second.IsFpuRegister()) { |
| 2696 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2697 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2698 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2699 | DCHECK(!const_area->NeedsMaterialization()); |
| 2700 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2701 | codegen_->LiteralDoubleAddress( |
| 2702 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2703 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2704 | } else { |
| 2705 | DCHECK(second.IsDoubleStackSlot()); |
| 2706 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2707 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2708 | break; |
| 2709 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2710 | |
| 2711 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2712 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2713 | } |
| 2714 | } |
| 2715 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2716 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 2717 | uint32_t temp_offset, |
| 2718 | uint32_t stack_adjustment, |
| 2719 | bool is_fp, |
| 2720 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2721 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2722 | DCHECK(!is_wide); |
| 2723 | if (is_fp) { |
| 2724 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2725 | } else { |
| 2726 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2727 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2728 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2729 | DCHECK(is_wide); |
| 2730 | if (is_fp) { |
| 2731 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2732 | } else { |
| 2733 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2734 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2735 | } else { |
| 2736 | // 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] | 2737 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2738 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2739 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2740 | if (is_fp) { |
| 2741 | __ flds(Address(ESP, temp_offset)); |
| 2742 | } else { |
| 2743 | __ filds(Address(ESP, temp_offset)); |
| 2744 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2745 | } else { |
| 2746 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2747 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2748 | if (is_fp) { |
| 2749 | __ fldl(Address(ESP, temp_offset)); |
| 2750 | } else { |
| 2751 | __ fildl(Address(ESP, temp_offset)); |
| 2752 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2753 | } |
| 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2758 | Primitive::Type type = rem->GetResultType(); |
| 2759 | bool is_float = type == Primitive::kPrimFloat; |
| 2760 | size_t elem_size = Primitive::ComponentSize(type); |
| 2761 | LocationSummary* locations = rem->GetLocations(); |
| 2762 | Location first = locations->InAt(0); |
| 2763 | Location second = locations->InAt(1); |
| 2764 | Location out = locations->Out(); |
| 2765 | |
| 2766 | // Create stack space for 2 elements. |
| 2767 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2768 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2769 | |
| 2770 | // 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] | 2771 | const bool is_wide = !is_float; |
| 2772 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 2773 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2774 | |
| 2775 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2776 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2777 | __ Bind(&retry); |
| 2778 | __ fprem(); |
| 2779 | |
| 2780 | // Move FP status to AX. |
| 2781 | __ fstsw(); |
| 2782 | |
| 2783 | // And see if the argument reduction is complete. This is signaled by the |
| 2784 | // C2 FPU flag bit set to 0. |
| 2785 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2786 | __ j(kNotEqual, &retry); |
| 2787 | |
| 2788 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2789 | // Store FP top of stack to real stack. |
| 2790 | if (is_float) { |
| 2791 | __ fsts(Address(ESP, 0)); |
| 2792 | } else { |
| 2793 | __ fstl(Address(ESP, 0)); |
| 2794 | } |
| 2795 | |
| 2796 | // Pop the 2 items from the FP stack. |
| 2797 | __ fucompp(); |
| 2798 | |
| 2799 | // Load the value from the stack into an XMM register. |
| 2800 | DCHECK(out.IsFpuRegister()) << out; |
| 2801 | if (is_float) { |
| 2802 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2803 | } else { |
| 2804 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2805 | } |
| 2806 | |
| 2807 | // And remove the temporary stack space we allocated. |
| 2808 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2809 | } |
| 2810 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2811 | |
| 2812 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2813 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2814 | |
| 2815 | LocationSummary* locations = instruction->GetLocations(); |
| 2816 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2817 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2818 | |
| 2819 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2820 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2821 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2822 | |
| 2823 | DCHECK(imm == 1 || imm == -1); |
| 2824 | |
| 2825 | if (instruction->IsRem()) { |
| 2826 | __ xorl(out_register, out_register); |
| 2827 | } else { |
| 2828 | __ movl(out_register, input_register); |
| 2829 | if (imm == -1) { |
| 2830 | __ negl(out_register); |
| 2831 | } |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2836 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2837 | LocationSummary* locations = instruction->GetLocations(); |
| 2838 | |
| 2839 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2840 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2841 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2842 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2843 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2844 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2845 | |
| 2846 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2847 | __ testl(input_register, input_register); |
| 2848 | __ cmovl(kGreaterEqual, num, input_register); |
| 2849 | int shift = CTZ(imm); |
| 2850 | __ sarl(num, Immediate(shift)); |
| 2851 | |
| 2852 | if (imm < 0) { |
| 2853 | __ negl(num); |
| 2854 | } |
| 2855 | |
| 2856 | __ movl(out_register, num); |
| 2857 | } |
| 2858 | |
| 2859 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2860 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2861 | |
| 2862 | LocationSummary* locations = instruction->GetLocations(); |
| 2863 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2864 | |
| 2865 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2866 | Register out = locations->Out().AsRegister<Register>(); |
| 2867 | Register num; |
| 2868 | Register edx; |
| 2869 | |
| 2870 | if (instruction->IsDiv()) { |
| 2871 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2872 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2873 | } else { |
| 2874 | edx = locations->Out().AsRegister<Register>(); |
| 2875 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2876 | } |
| 2877 | |
| 2878 | DCHECK_EQ(EAX, eax); |
| 2879 | DCHECK_EQ(EDX, edx); |
| 2880 | if (instruction->IsDiv()) { |
| 2881 | DCHECK_EQ(EAX, out); |
| 2882 | } else { |
| 2883 | DCHECK_EQ(EDX, out); |
| 2884 | } |
| 2885 | |
| 2886 | int64_t magic; |
| 2887 | int shift; |
| 2888 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2889 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2890 | NearLabel ndiv; |
| 2891 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2892 | // If numerator is 0, the result is 0, no computation needed. |
| 2893 | __ testl(eax, eax); |
| 2894 | __ j(kNotEqual, &ndiv); |
| 2895 | |
| 2896 | __ xorl(out, out); |
| 2897 | __ jmp(&end); |
| 2898 | |
| 2899 | __ Bind(&ndiv); |
| 2900 | |
| 2901 | // Save the numerator. |
| 2902 | __ movl(num, eax); |
| 2903 | |
| 2904 | // EAX = magic |
| 2905 | __ movl(eax, Immediate(magic)); |
| 2906 | |
| 2907 | // EDX:EAX = magic * numerator |
| 2908 | __ imull(num); |
| 2909 | |
| 2910 | if (imm > 0 && magic < 0) { |
| 2911 | // EDX += num |
| 2912 | __ addl(edx, num); |
| 2913 | } else if (imm < 0 && magic > 0) { |
| 2914 | __ subl(edx, num); |
| 2915 | } |
| 2916 | |
| 2917 | // Shift if needed. |
| 2918 | if (shift != 0) { |
| 2919 | __ sarl(edx, Immediate(shift)); |
| 2920 | } |
| 2921 | |
| 2922 | // EDX += 1 if EDX < 0 |
| 2923 | __ movl(eax, edx); |
| 2924 | __ shrl(edx, Immediate(31)); |
| 2925 | __ addl(edx, eax); |
| 2926 | |
| 2927 | if (instruction->IsRem()) { |
| 2928 | __ movl(eax, num); |
| 2929 | __ imull(edx, Immediate(imm)); |
| 2930 | __ subl(eax, edx); |
| 2931 | __ movl(edx, eax); |
| 2932 | } else { |
| 2933 | __ movl(eax, edx); |
| 2934 | } |
| 2935 | __ Bind(&end); |
| 2936 | } |
| 2937 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2938 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2939 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2940 | |
| 2941 | LocationSummary* locations = instruction->GetLocations(); |
| 2942 | Location out = locations->Out(); |
| 2943 | Location first = locations->InAt(0); |
| 2944 | Location second = locations->InAt(1); |
| 2945 | bool is_div = instruction->IsDiv(); |
| 2946 | |
| 2947 | switch (instruction->GetResultType()) { |
| 2948 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2949 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2950 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2951 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2952 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2953 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2954 | |
| 2955 | if (imm == 0) { |
| 2956 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2957 | } else if (imm == 1 || imm == -1) { |
| 2958 | DivRemOneOrMinusOne(instruction); |
| 2959 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2960 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2961 | } else { |
| 2962 | DCHECK(imm <= -2 || imm >= 2); |
| 2963 | GenerateDivRemWithAnyConstant(instruction); |
| 2964 | } |
| 2965 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 2966 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2967 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2968 | is_div); |
| 2969 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2970 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2971 | Register second_reg = second.AsRegister<Register>(); |
| 2972 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2973 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2974 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2975 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2976 | __ cmpl(second_reg, Immediate(-1)); |
| 2977 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2978 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2979 | // edx:eax <- sign-extended of eax |
| 2980 | __ cdq(); |
| 2981 | // eax = quotient, edx = remainder |
| 2982 | __ idivl(second_reg); |
| 2983 | __ Bind(slow_path->GetExitLabel()); |
| 2984 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2985 | break; |
| 2986 | } |
| 2987 | |
| 2988 | case Primitive::kPrimLong: { |
| 2989 | InvokeRuntimeCallingConvention calling_convention; |
| 2990 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2991 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2992 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2993 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2994 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2995 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2996 | |
| 2997 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2998 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2999 | instruction, |
| 3000 | instruction->GetDexPc(), |
| 3001 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3002 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 3003 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 3004 | instruction, |
| 3005 | instruction->GetDexPc(), |
| 3006 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3007 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3008 | break; |
| 3009 | } |
| 3010 | |
| 3011 | default: |
| 3012 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 3013 | } |
| 3014 | } |
| 3015 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3016 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3017 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3018 | ? LocationSummary::kCall |
| 3019 | : LocationSummary::kNoCall; |
| 3020 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 3021 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3022 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3023 | case Primitive::kPrimInt: { |
| 3024 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3025 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3026 | locations->SetOut(Location::SameAsFirstInput()); |
| 3027 | // Intel uses edx:eax as the dividend. |
| 3028 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3029 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3030 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3031 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3032 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3033 | locations->AddTemp(Location::RequiresRegister()); |
| 3034 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3035 | break; |
| 3036 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3037 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3038 | InvokeRuntimeCallingConvention calling_convention; |
| 3039 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3040 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3041 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3042 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3043 | // Runtime helper puts the result in EAX, EDX. |
| 3044 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3045 | break; |
| 3046 | } |
| 3047 | case Primitive::kPrimFloat: |
| 3048 | case Primitive::kPrimDouble: { |
| 3049 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3050 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3051 | locations->SetOut(Location::SameAsFirstInput()); |
| 3052 | break; |
| 3053 | } |
| 3054 | |
| 3055 | default: |
| 3056 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3061 | LocationSummary* locations = div->GetLocations(); |
| 3062 | Location first = locations->InAt(0); |
| 3063 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3064 | |
| 3065 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3066 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3067 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3068 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3069 | break; |
| 3070 | } |
| 3071 | |
| 3072 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3073 | if (second.IsFpuRegister()) { |
| 3074 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3075 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3076 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3077 | DCHECK(!const_area->NeedsMaterialization()); |
| 3078 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3079 | codegen_->LiteralFloatAddress( |
| 3080 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3081 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3082 | } else { |
| 3083 | DCHECK(second.IsStackSlot()); |
| 3084 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3085 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3086 | break; |
| 3087 | } |
| 3088 | |
| 3089 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3090 | if (second.IsFpuRegister()) { |
| 3091 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3092 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3093 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3094 | DCHECK(!const_area->NeedsMaterialization()); |
| 3095 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3096 | codegen_->LiteralDoubleAddress( |
| 3097 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3098 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3099 | } else { |
| 3100 | DCHECK(second.IsDoubleStackSlot()); |
| 3101 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3102 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3103 | break; |
| 3104 | } |
| 3105 | |
| 3106 | default: |
| 3107 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3108 | } |
| 3109 | } |
| 3110 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3111 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3112 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3113 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3114 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3115 | ? LocationSummary::kCall |
| 3116 | : LocationSummary::kNoCall; |
| 3117 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3118 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3119 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3120 | case Primitive::kPrimInt: { |
| 3121 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3122 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3123 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3124 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3125 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3126 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3127 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3128 | locations->AddTemp(Location::RequiresRegister()); |
| 3129 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3130 | break; |
| 3131 | } |
| 3132 | case Primitive::kPrimLong: { |
| 3133 | InvokeRuntimeCallingConvention calling_convention; |
| 3134 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3135 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3136 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3137 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3138 | // Runtime helper puts the result in EAX, EDX. |
| 3139 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3140 | break; |
| 3141 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3142 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3143 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3144 | locations->SetInAt(0, Location::Any()); |
| 3145 | locations->SetInAt(1, Location::Any()); |
| 3146 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3147 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3148 | break; |
| 3149 | } |
| 3150 | |
| 3151 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3152 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3153 | } |
| 3154 | } |
| 3155 | |
| 3156 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3157 | Primitive::Type type = rem->GetResultType(); |
| 3158 | switch (type) { |
| 3159 | case Primitive::kPrimInt: |
| 3160 | case Primitive::kPrimLong: { |
| 3161 | GenerateDivRemIntegral(rem); |
| 3162 | break; |
| 3163 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3164 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3165 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3166 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3167 | break; |
| 3168 | } |
| 3169 | default: |
| 3170 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3171 | } |
| 3172 | } |
| 3173 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3174 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3175 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3176 | ? LocationSummary::kCallOnSlowPath |
| 3177 | : LocationSummary::kNoCall; |
| 3178 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3179 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3180 | case Primitive::kPrimByte: |
| 3181 | case Primitive::kPrimChar: |
| 3182 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3183 | case Primitive::kPrimInt: { |
| 3184 | locations->SetInAt(0, Location::Any()); |
| 3185 | break; |
| 3186 | } |
| 3187 | case Primitive::kPrimLong: { |
| 3188 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3189 | if (!instruction->IsConstant()) { |
| 3190 | locations->AddTemp(Location::RequiresRegister()); |
| 3191 | } |
| 3192 | break; |
| 3193 | } |
| 3194 | default: |
| 3195 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3196 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3197 | if (instruction->HasUses()) { |
| 3198 | locations->SetOut(Location::SameAsFirstInput()); |
| 3199 | } |
| 3200 | } |
| 3201 | |
| 3202 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3203 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3204 | codegen_->AddSlowPath(slow_path); |
| 3205 | |
| 3206 | LocationSummary* locations = instruction->GetLocations(); |
| 3207 | Location value = locations->InAt(0); |
| 3208 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3209 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3210 | case Primitive::kPrimByte: |
| 3211 | case Primitive::kPrimChar: |
| 3212 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3213 | case Primitive::kPrimInt: { |
| 3214 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3215 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3216 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3217 | } else if (value.IsStackSlot()) { |
| 3218 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3219 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3220 | } else { |
| 3221 | DCHECK(value.IsConstant()) << value; |
| 3222 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3223 | __ jmp(slow_path->GetEntryLabel()); |
| 3224 | } |
| 3225 | } |
| 3226 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3227 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3228 | case Primitive::kPrimLong: { |
| 3229 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3230 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3231 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3232 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3233 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3234 | } else { |
| 3235 | DCHECK(value.IsConstant()) << value; |
| 3236 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3237 | __ jmp(slow_path->GetEntryLabel()); |
| 3238 | } |
| 3239 | } |
| 3240 | break; |
| 3241 | } |
| 3242 | default: |
| 3243 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3244 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3245 | } |
| 3246 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3247 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3248 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3249 | |
| 3250 | LocationSummary* locations = |
| 3251 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3252 | |
| 3253 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3254 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3255 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3256 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3257 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3258 | // The shift count needs to be in CL or a constant. |
| 3259 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3260 | locations->SetOut(Location::SameAsFirstInput()); |
| 3261 | break; |
| 3262 | } |
| 3263 | default: |
| 3264 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3269 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3270 | |
| 3271 | LocationSummary* locations = op->GetLocations(); |
| 3272 | Location first = locations->InAt(0); |
| 3273 | Location second = locations->InAt(1); |
| 3274 | DCHECK(first.Equals(locations->Out())); |
| 3275 | |
| 3276 | switch (op->GetResultType()) { |
| 3277 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3278 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3279 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3280 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3281 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3282 | DCHECK_EQ(ECX, second_reg); |
| 3283 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3284 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3285 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3286 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3287 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3288 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3289 | } |
| 3290 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3291 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3292 | if (shift == 0) { |
| 3293 | return; |
| 3294 | } |
| 3295 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3296 | if (op->IsShl()) { |
| 3297 | __ shll(first_reg, imm); |
| 3298 | } else if (op->IsShr()) { |
| 3299 | __ sarl(first_reg, imm); |
| 3300 | } else { |
| 3301 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | break; |
| 3305 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3306 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3307 | if (second.IsRegister()) { |
| 3308 | Register second_reg = second.AsRegister<Register>(); |
| 3309 | DCHECK_EQ(ECX, second_reg); |
| 3310 | if (op->IsShl()) { |
| 3311 | GenerateShlLong(first, second_reg); |
| 3312 | } else if (op->IsShr()) { |
| 3313 | GenerateShrLong(first, second_reg); |
| 3314 | } else { |
| 3315 | GenerateUShrLong(first, second_reg); |
| 3316 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3317 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3318 | // Shift by a constant. |
| 3319 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3320 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3321 | if (shift != 0) { |
| 3322 | if (op->IsShl()) { |
| 3323 | GenerateShlLong(first, shift); |
| 3324 | } else if (op->IsShr()) { |
| 3325 | GenerateShrLong(first, shift); |
| 3326 | } else { |
| 3327 | GenerateUShrLong(first, shift); |
| 3328 | } |
| 3329 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3330 | } |
| 3331 | break; |
| 3332 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3333 | default: |
| 3334 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3335 | } |
| 3336 | } |
| 3337 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3338 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3339 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3340 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3341 | if (shift == 1) { |
| 3342 | // This is just an addition. |
| 3343 | __ addl(low, low); |
| 3344 | __ adcl(high, high); |
| 3345 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3346 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3347 | codegen_->EmitParallelMoves( |
| 3348 | loc.ToLow(), |
| 3349 | loc.ToHigh(), |
| 3350 | Primitive::kPrimInt, |
| 3351 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3352 | loc.ToLow(), |
| 3353 | Primitive::kPrimInt); |
| 3354 | } else if (shift > 32) { |
| 3355 | // Low part becomes 0. High part is low part << (shift-32). |
| 3356 | __ movl(high, low); |
| 3357 | __ shll(high, Immediate(shift - 32)); |
| 3358 | __ xorl(low, low); |
| 3359 | } else { |
| 3360 | // Between 1 and 31. |
| 3361 | __ shld(high, low, Immediate(shift)); |
| 3362 | __ shll(low, Immediate(shift)); |
| 3363 | } |
| 3364 | } |
| 3365 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3366 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3367 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3368 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3369 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3370 | __ testl(shifter, Immediate(32)); |
| 3371 | __ j(kEqual, &done); |
| 3372 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3373 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3374 | __ Bind(&done); |
| 3375 | } |
| 3376 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3377 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3378 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3379 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3380 | if (shift == 32) { |
| 3381 | // Need to copy the sign. |
| 3382 | DCHECK_NE(low, high); |
| 3383 | __ movl(low, high); |
| 3384 | __ sarl(high, Immediate(31)); |
| 3385 | } else if (shift > 32) { |
| 3386 | DCHECK_NE(low, high); |
| 3387 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3388 | __ movl(low, high); |
| 3389 | __ sarl(high, Immediate(31)); |
| 3390 | __ sarl(low, Immediate(shift - 32)); |
| 3391 | } else { |
| 3392 | // Between 1 and 31. |
| 3393 | __ shrd(low, high, Immediate(shift)); |
| 3394 | __ sarl(high, Immediate(shift)); |
| 3395 | } |
| 3396 | } |
| 3397 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3398 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3399 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3400 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3401 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3402 | __ testl(shifter, Immediate(32)); |
| 3403 | __ j(kEqual, &done); |
| 3404 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3405 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3406 | __ Bind(&done); |
| 3407 | } |
| 3408 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3409 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3410 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3411 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3412 | if (shift == 32) { |
| 3413 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3414 | codegen_->EmitParallelMoves( |
| 3415 | loc.ToHigh(), |
| 3416 | loc.ToLow(), |
| 3417 | Primitive::kPrimInt, |
| 3418 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3419 | loc.ToHigh(), |
| 3420 | Primitive::kPrimInt); |
| 3421 | } else if (shift > 32) { |
| 3422 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3423 | __ movl(low, high); |
| 3424 | __ shrl(low, Immediate(shift - 32)); |
| 3425 | __ xorl(high, high); |
| 3426 | } else { |
| 3427 | // Between 1 and 31. |
| 3428 | __ shrd(low, high, Immediate(shift)); |
| 3429 | __ shrl(high, Immediate(shift)); |
| 3430 | } |
| 3431 | } |
| 3432 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3433 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3434 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3435 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3436 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3437 | __ testl(shifter, Immediate(32)); |
| 3438 | __ j(kEqual, &done); |
| 3439 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3440 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3441 | __ Bind(&done); |
| 3442 | } |
| 3443 | |
| 3444 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3445 | HandleShift(shl); |
| 3446 | } |
| 3447 | |
| 3448 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3449 | HandleShift(shl); |
| 3450 | } |
| 3451 | |
| 3452 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3453 | HandleShift(shr); |
| 3454 | } |
| 3455 | |
| 3456 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3457 | HandleShift(shr); |
| 3458 | } |
| 3459 | |
| 3460 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3461 | HandleShift(ushr); |
| 3462 | } |
| 3463 | |
| 3464 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3465 | HandleShift(ushr); |
| 3466 | } |
| 3467 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3468 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3469 | LocationSummary* locations = |
| 3470 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3471 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3472 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3473 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3474 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 3478 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3479 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3480 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3481 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3482 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3483 | instruction, |
| 3484 | instruction->GetDexPc(), |
| 3485 | nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3486 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3487 | } |
| 3488 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3489 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3490 | LocationSummary* locations = |
| 3491 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3492 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3493 | InvokeRuntimeCallingConvention calling_convention; |
| 3494 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3495 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3496 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3500 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3501 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 3502 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3503 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3504 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3505 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3506 | instruction, |
| 3507 | instruction->GetDexPc(), |
| 3508 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3509 | DCHECK(!codegen_->IsLeafMethod()); |
| 3510 | } |
| 3511 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3512 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3513 | LocationSummary* locations = |
| 3514 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3515 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3516 | if (location.IsStackSlot()) { |
| 3517 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3518 | } else if (location.IsDoubleStackSlot()) { |
| 3519 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3520 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3521 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3522 | } |
| 3523 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3524 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3525 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3526 | } |
| 3527 | |
| 3528 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3529 | LocationSummary* locations = |
| 3530 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3531 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3532 | } |
| 3533 | |
| 3534 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3535 | } |
| 3536 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3537 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3538 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3539 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3540 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3541 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3542 | } |
| 3543 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3544 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3545 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3546 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3547 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3548 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3549 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3550 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3551 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3552 | break; |
| 3553 | |
| 3554 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3555 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3556 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3557 | break; |
| 3558 | |
| 3559 | default: |
| 3560 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3561 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3562 | } |
| 3563 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3564 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3565 | LocationSummary* locations = |
| 3566 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3567 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3568 | locations->SetOut(Location::SameAsFirstInput()); |
| 3569 | } |
| 3570 | |
| 3571 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3572 | LocationSummary* locations = bool_not->GetLocations(); |
| 3573 | Location in = locations->InAt(0); |
| 3574 | Location out = locations->Out(); |
| 3575 | DCHECK(in.Equals(out)); |
| 3576 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3577 | } |
| 3578 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3579 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3580 | LocationSummary* locations = |
| 3581 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3582 | switch (compare->InputAt(0)->GetType()) { |
| 3583 | case Primitive::kPrimLong: { |
| 3584 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3585 | locations->SetInAt(1, Location::Any()); |
| 3586 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3587 | break; |
| 3588 | } |
| 3589 | case Primitive::kPrimFloat: |
| 3590 | case Primitive::kPrimDouble: { |
| 3591 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3592 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3593 | locations->SetOut(Location::RequiresRegister()); |
| 3594 | break; |
| 3595 | } |
| 3596 | default: |
| 3597 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3598 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3602 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3603 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3604 | Location left = locations->InAt(0); |
| 3605 | Location right = locations->InAt(1); |
| 3606 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3607 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3608 | switch (compare->InputAt(0)->GetType()) { |
| 3609 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3610 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 3611 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 3612 | int32_t val_low = 0; |
| 3613 | int32_t val_high = 0; |
| 3614 | bool right_is_const = false; |
| 3615 | |
| 3616 | if (right.IsConstant()) { |
| 3617 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 3618 | right_is_const = true; |
| 3619 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 3620 | val_low = Low32Bits(val); |
| 3621 | val_high = High32Bits(val); |
| 3622 | } |
| 3623 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3624 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3625 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3626 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3627 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3628 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3629 | DCHECK(right_is_const) << right; |
| 3630 | if (val_high == 0) { |
| 3631 | __ testl(left_high, left_high); |
| 3632 | } else { |
| 3633 | __ cmpl(left_high, Immediate(val_high)); |
| 3634 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3635 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3636 | __ j(kLess, &less); // Signed compare. |
| 3637 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3638 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3639 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3640 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3641 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3642 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3643 | DCHECK(right_is_const) << right; |
| 3644 | if (val_low == 0) { |
| 3645 | __ testl(left_low, left_low); |
| 3646 | } else { |
| 3647 | __ cmpl(left_low, Immediate(val_low)); |
| 3648 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3649 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3650 | break; |
| 3651 | } |
| 3652 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3653 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3654 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3655 | break; |
| 3656 | } |
| 3657 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3658 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3659 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3660 | break; |
| 3661 | } |
| 3662 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3663 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3664 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3665 | __ movl(out, Immediate(0)); |
| 3666 | __ j(kEqual, &done); |
| 3667 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3668 | |
| 3669 | __ Bind(&greater); |
| 3670 | __ movl(out, Immediate(1)); |
| 3671 | __ jmp(&done); |
| 3672 | |
| 3673 | __ Bind(&less); |
| 3674 | __ movl(out, Immediate(-1)); |
| 3675 | |
| 3676 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3677 | } |
| 3678 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3679 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3680 | LocationSummary* locations = |
| 3681 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3682 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3683 | locations->SetInAt(i, Location::Any()); |
| 3684 | } |
| 3685 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3686 | } |
| 3687 | |
| 3688 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3689 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3690 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3691 | } |
| 3692 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3693 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3694 | /* |
| 3695 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3696 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3697 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3698 | */ |
| 3699 | switch (kind) { |
| 3700 | case MemBarrierKind::kAnyAny: { |
| 3701 | __ mfence(); |
| 3702 | break; |
| 3703 | } |
| 3704 | case MemBarrierKind::kAnyStore: |
| 3705 | case MemBarrierKind::kLoadAny: |
| 3706 | case MemBarrierKind::kStoreStore: { |
| 3707 | // nop |
| 3708 | break; |
| 3709 | } |
| 3710 | default: |
| 3711 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3712 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3713 | } |
| 3714 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3715 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3716 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 3717 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3718 | switch (invoke->GetMethodLoadKind()) { |
| 3719 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3720 | // temp = thread->string_init_entrypoint |
| 3721 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 3722 | break; |
| 3723 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 3724 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3725 | break; |
| 3726 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3727 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 3728 | break; |
| 3729 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3730 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 3731 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3732 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 3733 | break; |
| 3734 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 3735 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 3736 | FALLTHROUGH_INTENDED; |
| 3737 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 3738 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3739 | Register method_reg; |
| 3740 | Register reg = temp.AsRegister<Register>(); |
| 3741 | if (current_method.IsRegister()) { |
| 3742 | method_reg = current_method.AsRegister<Register>(); |
| 3743 | } else { |
| 3744 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 3745 | DCHECK(!current_method.IsValid()); |
| 3746 | method_reg = reg; |
| 3747 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 3748 | } |
| 3749 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3750 | __ movl(reg, Address(method_reg, |
| 3751 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3752 | // temp = temp[index_in_cache] |
| 3753 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3754 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 3755 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3756 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | switch (invoke->GetCodePtrLocation()) { |
| 3760 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3761 | __ call(GetFrameEntryLabel()); |
| 3762 | break; |
| 3763 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3764 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3765 | Label* label = &relative_call_patches_.back().label; |
| 3766 | __ call(label); // Bind to the patch label, override at link time. |
| 3767 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 3768 | break; |
| 3769 | } |
| 3770 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3771 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3772 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 3773 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 3774 | FALLTHROUGH_INTENDED; |
| 3775 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3776 | // (callee_method + offset_of_quick_compiled_code)() |
| 3777 | __ call(Address(callee_method.AsRegister<Register>(), |
| 3778 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3779 | kX86WordSize).Int32Value())); |
| 3780 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3784 | } |
| 3785 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3786 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 3787 | Register temp = temp_in.AsRegister<Register>(); |
| 3788 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3789 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| 3790 | LocationSummary* locations = invoke->GetLocations(); |
| 3791 | Location receiver = locations->InAt(0); |
| 3792 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3793 | // temp = object->GetClass(); |
| 3794 | DCHECK(receiver.IsRegister()); |
| 3795 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| 3796 | MaybeRecordImplicitNullCheck(invoke); |
| 3797 | __ MaybeUnpoisonHeapReference(temp); |
| 3798 | // temp = temp->GetMethodAt(method_offset); |
| 3799 | __ movl(temp, Address(temp, method_offset)); |
| 3800 | // call temp->GetEntryPoint(); |
| 3801 | __ call(Address( |
| 3802 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 3803 | } |
| 3804 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3805 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3806 | DCHECK(linker_patches->empty()); |
| 3807 | linker_patches->reserve(method_patches_.size() + relative_call_patches_.size()); |
| 3808 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 3809 | // The label points to the end of the "movl" insn but the literal offset for method |
| 3810 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3811 | uint32_t literal_offset = info.label.Position() - 4; |
| 3812 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 3813 | info.target_method.dex_file, |
| 3814 | info.target_method.dex_method_index)); |
| 3815 | } |
| 3816 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 3817 | // The label points to the end of the "call" insn but the literal offset for method |
| 3818 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3819 | uint32_t literal_offset = info.label.Position() - 4; |
| 3820 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 3821 | info.target_method.dex_file, |
| 3822 | info.target_method.dex_method_index)); |
| 3823 | } |
| 3824 | } |
| 3825 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3826 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 3827 | Register card, |
| 3828 | Register object, |
| 3829 | Register value, |
| 3830 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3831 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3832 | if (value_can_be_null) { |
| 3833 | __ testl(value, value); |
| 3834 | __ j(kEqual, &is_null); |
| 3835 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3836 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3837 | __ movl(temp, object); |
| 3838 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3839 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3840 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3841 | if (value_can_be_null) { |
| 3842 | __ Bind(&is_null); |
| 3843 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3844 | } |
| 3845 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3846 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3847 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3848 | LocationSummary* locations = |
| 3849 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3850 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3851 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3852 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3853 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3854 | } else { |
| 3855 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3856 | // the object's location. |
| 3857 | locations->SetOut(Location::RequiresRegister(), |
| 3858 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3859 | : Location::kNoOutputOverlap); |
| 3860 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3861 | |
| 3862 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3863 | // Long values can be loaded atomically into an XMM using movsd. |
| 3864 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3865 | // and then copy the XMM into the output 32bits at a time). |
| 3866 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3867 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3868 | } |
| 3869 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3870 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3871 | const FieldInfo& field_info) { |
| 3872 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3873 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3874 | LocationSummary* locations = instruction->GetLocations(); |
| 3875 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3876 | Location out = locations->Out(); |
| 3877 | bool is_volatile = field_info.IsVolatile(); |
| 3878 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3879 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3880 | |
| 3881 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3882 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3883 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3884 | break; |
| 3885 | } |
| 3886 | |
| 3887 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3888 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3889 | break; |
| 3890 | } |
| 3891 | |
| 3892 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3893 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3894 | break; |
| 3895 | } |
| 3896 | |
| 3897 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3898 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3899 | break; |
| 3900 | } |
| 3901 | |
| 3902 | case Primitive::kPrimInt: |
| 3903 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3904 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3905 | break; |
| 3906 | } |
| 3907 | |
| 3908 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3909 | if (is_volatile) { |
| 3910 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3911 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3912 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3913 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3914 | __ psrlq(temp, Immediate(32)); |
| 3915 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3916 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3917 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3918 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3919 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3920 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3921 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3922 | break; |
| 3923 | } |
| 3924 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3925 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3926 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3927 | break; |
| 3928 | } |
| 3929 | |
| 3930 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3931 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3932 | break; |
| 3933 | } |
| 3934 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3935 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3936 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3937 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3938 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3939 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3940 | // Longs are handled in the switch. |
| 3941 | if (field_type != Primitive::kPrimLong) { |
| 3942 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3943 | } |
| 3944 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3945 | if (is_volatile) { |
| 3946 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3947 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3948 | |
| 3949 | if (field_type == Primitive::kPrimNot) { |
| 3950 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3951 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3952 | } |
| 3953 | |
| 3954 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3955 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3956 | |
| 3957 | LocationSummary* locations = |
| 3958 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3959 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3960 | bool is_volatile = field_info.IsVolatile(); |
| 3961 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3962 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3963 | || (field_type == Primitive::kPrimByte); |
| 3964 | |
| 3965 | // The register allocator does not support multiple |
| 3966 | // inputs that die at entry with one in a specific register. |
| 3967 | if (is_byte_type) { |
| 3968 | // Ensure the value is in a byte register. |
| 3969 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3970 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3971 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3972 | } else { |
| 3973 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3974 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3975 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3976 | // Temporary registers for the write barrier. |
| 3977 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3978 | // Ensure the card is in a byte register. |
| 3979 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3980 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3981 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3982 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3983 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3984 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3985 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3986 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3987 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3988 | } |
| 3989 | } |
| 3990 | |
| 3991 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3992 | const FieldInfo& field_info, |
| 3993 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3994 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3995 | |
| 3996 | LocationSummary* locations = instruction->GetLocations(); |
| 3997 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3998 | Location value = locations->InAt(1); |
| 3999 | bool is_volatile = field_info.IsVolatile(); |
| 4000 | Primitive::Type field_type = field_info.GetFieldType(); |
| 4001 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4002 | bool needs_write_barrier = |
| 4003 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4004 | |
| 4005 | if (is_volatile) { |
| 4006 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 4007 | } |
| 4008 | |
| 4009 | switch (field_type) { |
| 4010 | case Primitive::kPrimBoolean: |
| 4011 | case Primitive::kPrimByte: { |
| 4012 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 4013 | break; |
| 4014 | } |
| 4015 | |
| 4016 | case Primitive::kPrimShort: |
| 4017 | case Primitive::kPrimChar: { |
| 4018 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 4019 | break; |
| 4020 | } |
| 4021 | |
| 4022 | case Primitive::kPrimInt: |
| 4023 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4024 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 4025 | // Note that in the case where `value` is a null reference, |
| 4026 | // we do not enter this block, as the reference does not |
| 4027 | // need poisoning. |
| 4028 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 4029 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4030 | __ movl(temp, value.AsRegister<Register>()); |
| 4031 | __ PoisonHeapReference(temp); |
| 4032 | __ movl(Address(base, offset), temp); |
| 4033 | } else { |
| 4034 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4035 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4036 | break; |
| 4037 | } |
| 4038 | |
| 4039 | case Primitive::kPrimLong: { |
| 4040 | if (is_volatile) { |
| 4041 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4042 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4043 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4044 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4045 | __ punpckldq(temp1, temp2); |
| 4046 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4047 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4048 | } else { |
| 4049 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4050 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4051 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4052 | } |
| 4053 | break; |
| 4054 | } |
| 4055 | |
| 4056 | case Primitive::kPrimFloat: { |
| 4057 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4058 | break; |
| 4059 | } |
| 4060 | |
| 4061 | case Primitive::kPrimDouble: { |
| 4062 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4063 | break; |
| 4064 | } |
| 4065 | |
| 4066 | case Primitive::kPrimVoid: |
| 4067 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4068 | UNREACHABLE(); |
| 4069 | } |
| 4070 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4071 | // Longs are handled in the switch. |
| 4072 | if (field_type != Primitive::kPrimLong) { |
| 4073 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4074 | } |
| 4075 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4076 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4077 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4078 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4079 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4080 | } |
| 4081 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4082 | if (is_volatile) { |
| 4083 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4084 | } |
| 4085 | } |
| 4086 | |
| 4087 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4088 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4089 | } |
| 4090 | |
| 4091 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4092 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4093 | } |
| 4094 | |
| 4095 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4096 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4097 | } |
| 4098 | |
| 4099 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4100 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4101 | } |
| 4102 | |
| 4103 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4104 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4105 | } |
| 4106 | |
| 4107 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4108 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4109 | } |
| 4110 | |
| 4111 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4112 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4113 | } |
| 4114 | |
| 4115 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4116 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4117 | } |
| 4118 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame^] | 4119 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( |
| 4120 | HUnresolvedInstanceFieldGet* instruction) { |
| 4121 | FieldAccessCallingConventionX86 calling_convention; |
| 4122 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4123 | instruction, instruction->GetFieldType(), calling_convention); |
| 4124 | } |
| 4125 | |
| 4126 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( |
| 4127 | HUnresolvedInstanceFieldGet* instruction) { |
| 4128 | FieldAccessCallingConventionX86 calling_convention; |
| 4129 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4130 | instruction->GetFieldType(), |
| 4131 | instruction->GetFieldIndex(), |
| 4132 | instruction->GetDexPc(), |
| 4133 | calling_convention); |
| 4134 | } |
| 4135 | |
| 4136 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( |
| 4137 | HUnresolvedInstanceFieldSet* instruction) { |
| 4138 | FieldAccessCallingConventionX86 calling_convention; |
| 4139 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4140 | instruction, instruction->GetFieldType(), calling_convention); |
| 4141 | } |
| 4142 | |
| 4143 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( |
| 4144 | HUnresolvedInstanceFieldSet* instruction) { |
| 4145 | FieldAccessCallingConventionX86 calling_convention; |
| 4146 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4147 | instruction->GetFieldType(), |
| 4148 | instruction->GetFieldIndex(), |
| 4149 | instruction->GetDexPc(), |
| 4150 | calling_convention); |
| 4151 | } |
| 4152 | |
| 4153 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( |
| 4154 | HUnresolvedStaticFieldGet* instruction) { |
| 4155 | FieldAccessCallingConventionX86 calling_convention; |
| 4156 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4157 | instruction, instruction->GetFieldType(), calling_convention); |
| 4158 | } |
| 4159 | |
| 4160 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( |
| 4161 | HUnresolvedStaticFieldGet* instruction) { |
| 4162 | FieldAccessCallingConventionX86 calling_convention; |
| 4163 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4164 | instruction->GetFieldType(), |
| 4165 | instruction->GetFieldIndex(), |
| 4166 | instruction->GetDexPc(), |
| 4167 | calling_convention); |
| 4168 | } |
| 4169 | |
| 4170 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( |
| 4171 | HUnresolvedStaticFieldSet* instruction) { |
| 4172 | FieldAccessCallingConventionX86 calling_convention; |
| 4173 | codegen_->CreateUnresolvedFieldLocationSummary( |
| 4174 | instruction, instruction->GetFieldType(), calling_convention); |
| 4175 | } |
| 4176 | |
| 4177 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( |
| 4178 | HUnresolvedStaticFieldSet* instruction) { |
| 4179 | FieldAccessCallingConventionX86 calling_convention; |
| 4180 | codegen_->GenerateUnresolvedFieldAccess(instruction, |
| 4181 | instruction->GetFieldType(), |
| 4182 | instruction->GetFieldIndex(), |
| 4183 | instruction->GetDexPc(), |
| 4184 | calling_convention); |
| 4185 | } |
| 4186 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4187 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4188 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4189 | ? LocationSummary::kCallOnSlowPath |
| 4190 | : LocationSummary::kNoCall; |
| 4191 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4192 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4193 | ? Location::RequiresRegister() |
| 4194 | : Location::Any(); |
| 4195 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4196 | if (instruction->HasUses()) { |
| 4197 | locations->SetOut(Location::SameAsFirstInput()); |
| 4198 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4199 | } |
| 4200 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4201 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4202 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4203 | return; |
| 4204 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4205 | LocationSummary* locations = instruction->GetLocations(); |
| 4206 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4207 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4208 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4209 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4210 | } |
| 4211 | |
| 4212 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4213 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4214 | codegen_->AddSlowPath(slow_path); |
| 4215 | |
| 4216 | LocationSummary* locations = instruction->GetLocations(); |
| 4217 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4218 | |
| 4219 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4220 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4221 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4222 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4223 | } else { |
| 4224 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4225 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4226 | __ jmp(slow_path->GetEntryLabel()); |
| 4227 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4228 | } |
| 4229 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4230 | } |
| 4231 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4232 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4233 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4234 | GenerateImplicitNullCheck(instruction); |
| 4235 | } else { |
| 4236 | GenerateExplicitNullCheck(instruction); |
| 4237 | } |
| 4238 | } |
| 4239 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4240 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4241 | LocationSummary* locations = |
| 4242 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4243 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4244 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4245 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4246 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4247 | } else { |
| 4248 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 4249 | // the array's location. |
| 4250 | locations->SetOut(Location::RequiresRegister(), |
| 4251 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 4252 | : Location::kNoOutputOverlap); |
| 4253 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4257 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4258 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4259 | Location index = locations->InAt(1); |
| 4260 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4261 | Primitive::Type type = instruction->GetType(); |
| 4262 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4263 | case Primitive::kPrimBoolean: { |
| 4264 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4265 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4266 | if (index.IsConstant()) { |
| 4267 | __ movzxb(out, Address(obj, |
| 4268 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4269 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4270 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4271 | } |
| 4272 | break; |
| 4273 | } |
| 4274 | |
| 4275 | case Primitive::kPrimByte: { |
| 4276 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4277 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4278 | if (index.IsConstant()) { |
| 4279 | __ movsxb(out, Address(obj, |
| 4280 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4281 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4282 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4283 | } |
| 4284 | break; |
| 4285 | } |
| 4286 | |
| 4287 | case Primitive::kPrimShort: { |
| 4288 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4289 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4290 | if (index.IsConstant()) { |
| 4291 | __ movsxw(out, Address(obj, |
| 4292 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4293 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4294 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4295 | } |
| 4296 | break; |
| 4297 | } |
| 4298 | |
| 4299 | case Primitive::kPrimChar: { |
| 4300 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4301 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4302 | if (index.IsConstant()) { |
| 4303 | __ movzxw(out, Address(obj, |
| 4304 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4305 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4306 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4307 | } |
| 4308 | break; |
| 4309 | } |
| 4310 | |
| 4311 | case Primitive::kPrimInt: |
| 4312 | case Primitive::kPrimNot: { |
| 4313 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4314 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4315 | if (index.IsConstant()) { |
| 4316 | __ movl(out, Address(obj, |
| 4317 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4318 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4319 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4320 | } |
| 4321 | break; |
| 4322 | } |
| 4323 | |
| 4324 | case Primitive::kPrimLong: { |
| 4325 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4326 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4327 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4328 | if (index.IsConstant()) { |
| 4329 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4330 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4331 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4332 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4333 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4334 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4335 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4336 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4337 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4338 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4339 | } |
| 4340 | break; |
| 4341 | } |
| 4342 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4343 | case Primitive::kPrimFloat: { |
| 4344 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4345 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4346 | if (index.IsConstant()) { |
| 4347 | __ movss(out, Address(obj, |
| 4348 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4349 | } else { |
| 4350 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4351 | } |
| 4352 | break; |
| 4353 | } |
| 4354 | |
| 4355 | case Primitive::kPrimDouble: { |
| 4356 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4357 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4358 | if (index.IsConstant()) { |
| 4359 | __ movsd(out, Address(obj, |
| 4360 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4361 | } else { |
| 4362 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 4363 | } |
| 4364 | break; |
| 4365 | } |
| 4366 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4367 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4368 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4369 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4370 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4371 | |
| 4372 | if (type != Primitive::kPrimLong) { |
| 4373 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4374 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4375 | |
| 4376 | if (type == Primitive::kPrimNot) { |
| 4377 | Register out = locations->Out().AsRegister<Register>(); |
| 4378 | __ MaybeUnpoisonHeapReference(out); |
| 4379 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4380 | } |
| 4381 | |
| 4382 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4383 | // This location builder might end up asking to up to four registers, which is |
| 4384 | // not currently possible for baseline. The situation in which we need four |
| 4385 | // registers cannot be met by baseline though, because it has not run any |
| 4386 | // optimization. |
| 4387 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4388 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4389 | bool needs_write_barrier = |
| 4390 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 4391 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4392 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4393 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4394 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4395 | instruction, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4396 | may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4397 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4398 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4399 | || (value_type == Primitive::kPrimByte); |
| 4400 | // We need the inputs to be different than the output in case of long operation. |
| 4401 | // In case of a byte operation, the register allocator does not support multiple |
| 4402 | // inputs that die at entry with one in a specific register. |
| 4403 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4404 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4405 | if (is_byte_type) { |
| 4406 | // Ensure the value is in a byte register. |
| 4407 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 4408 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 4409 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4410 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4411 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4412 | } |
| 4413 | if (needs_write_barrier) { |
| 4414 | // Temporary registers for the write barrier. |
| 4415 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 4416 | // Ensure the card is in a byte register. |
| 4417 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4418 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4422 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4423 | Register array = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4424 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4425 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4426 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4427 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4428 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4429 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4430 | bool may_need_runtime_call = locations->CanCall(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4431 | bool needs_write_barrier = |
| 4432 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4433 | |
| 4434 | switch (value_type) { |
| 4435 | case Primitive::kPrimBoolean: |
| 4436 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4437 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4438 | Address address = index.IsConstant() |
| 4439 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4440 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 4441 | if (value.IsRegister()) { |
| 4442 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4443 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4444 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4445 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4446 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4447 | break; |
| 4448 | } |
| 4449 | |
| 4450 | case Primitive::kPrimShort: |
| 4451 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4452 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4453 | Address address = index.IsConstant() |
| 4454 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4455 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 4456 | if (value.IsRegister()) { |
| 4457 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4458 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4459 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4460 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4461 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4462 | break; |
| 4463 | } |
| 4464 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4465 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4466 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4467 | Address address = index.IsConstant() |
| 4468 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4469 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 4470 | if (!value.IsRegister()) { |
| 4471 | // Just setting null. |
| 4472 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4473 | DCHECK(value.IsConstant()) << value; |
| 4474 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4475 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4476 | DCHECK(!needs_write_barrier); |
| 4477 | DCHECK(!may_need_runtime_call); |
| 4478 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4479 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4480 | |
| 4481 | DCHECK(needs_write_barrier); |
| 4482 | Register register_value = value.AsRegister<Register>(); |
| 4483 | NearLabel done, not_null, do_put; |
| 4484 | SlowPathCode* slow_path = nullptr; |
| 4485 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4486 | if (may_need_runtime_call) { |
| 4487 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 4488 | codegen_->AddSlowPath(slow_path); |
| 4489 | if (instruction->GetValueCanBeNull()) { |
| 4490 | __ testl(register_value, register_value); |
| 4491 | __ j(kNotEqual, ¬_null); |
| 4492 | __ movl(address, Immediate(0)); |
| 4493 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4494 | __ jmp(&done); |
| 4495 | __ Bind(¬_null); |
| 4496 | } |
| 4497 | |
| 4498 | __ movl(temp, Address(array, class_offset)); |
| 4499 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4500 | __ MaybeUnpoisonHeapReference(temp); |
| 4501 | __ movl(temp, Address(temp, component_offset)); |
| 4502 | // No need to poison/unpoison, we're comparing two poisoned references. |
| 4503 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4504 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4505 | __ j(kEqual, &do_put); |
| 4506 | __ MaybeUnpoisonHeapReference(temp); |
| 4507 | __ movl(temp, Address(temp, super_offset)); |
| 4508 | // No need to unpoison, we're comparing against null.. |
| 4509 | __ testl(temp, temp); |
| 4510 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4511 | __ Bind(&do_put); |
| 4512 | } else { |
| 4513 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | if (kPoisonHeapReferences) { |
| 4518 | __ movl(temp, register_value); |
| 4519 | __ PoisonHeapReference(temp); |
| 4520 | __ movl(address, temp); |
| 4521 | } else { |
| 4522 | __ movl(address, register_value); |
| 4523 | } |
| 4524 | if (!may_need_runtime_call) { |
| 4525 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4526 | } |
| 4527 | |
| 4528 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 4529 | codegen_->MarkGCCard( |
| 4530 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 4531 | __ Bind(&done); |
| 4532 | |
| 4533 | if (slow_path != nullptr) { |
| 4534 | __ Bind(slow_path->GetExitLabel()); |
| 4535 | } |
| 4536 | |
| 4537 | break; |
| 4538 | } |
| 4539 | case Primitive::kPrimInt: { |
| 4540 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4541 | Address address = index.IsConstant() |
| 4542 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4543 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 4544 | if (value.IsRegister()) { |
| 4545 | __ movl(address, value.AsRegister<Register>()); |
| 4546 | } else { |
| 4547 | DCHECK(value.IsConstant()) << value; |
| 4548 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4549 | __ movl(address, Immediate(v)); |
| 4550 | } |
| 4551 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4552 | break; |
| 4553 | } |
| 4554 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4555 | case Primitive::kPrimLong: { |
| 4556 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4557 | if (index.IsConstant()) { |
| 4558 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4559 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4560 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4561 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4562 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4563 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4564 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4565 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4566 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4567 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4568 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4569 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4570 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4571 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4572 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4573 | value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4574 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4575 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4576 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4577 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4578 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4579 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4580 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4581 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4582 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4583 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4584 | Immediate(High32Bits(val))); |
| 4585 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4586 | } |
| 4587 | break; |
| 4588 | } |
| 4589 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4590 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4591 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4592 | Address address = index.IsConstant() |
| 4593 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4594 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4595 | DCHECK(value.IsFpuRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4596 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4597 | break; |
| 4598 | } |
| 4599 | |
| 4600 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4601 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4602 | Address address = index.IsConstant() |
| 4603 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4604 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4605 | DCHECK(value.IsFpuRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4606 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4607 | break; |
| 4608 | } |
| 4609 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4610 | case Primitive::kPrimVoid: |
| 4611 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4612 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 4617 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4618 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4619 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 4623 | LocationSummary* locations = instruction->GetLocations(); |
| 4624 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4625 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4626 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4627 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4628 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4632 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4633 | ? LocationSummary::kCallOnSlowPath |
| 4634 | : LocationSummary::kNoCall; |
| 4635 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4636 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4637 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4638 | if (instruction->HasUses()) { |
| 4639 | locations->SetOut(Location::SameAsFirstInput()); |
| 4640 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4644 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4645 | Location index_loc = locations->InAt(0); |
| 4646 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4647 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4648 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4649 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4650 | if (length_loc.IsConstant()) { |
| 4651 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4652 | if (index_loc.IsConstant()) { |
| 4653 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4654 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4655 | if (index < 0 || index >= length) { |
| 4656 | codegen_->AddSlowPath(slow_path); |
| 4657 | __ jmp(slow_path->GetEntryLabel()); |
| 4658 | } else { |
| 4659 | // Some optimization after BCE may have generated this, and we should not |
| 4660 | // generate a bounds check if it is a valid range. |
| 4661 | } |
| 4662 | return; |
| 4663 | } |
| 4664 | |
| 4665 | // We have to reverse the jump condition because the length is the constant. |
| 4666 | Register index_reg = index_loc.AsRegister<Register>(); |
| 4667 | __ cmpl(index_reg, Immediate(length)); |
| 4668 | codegen_->AddSlowPath(slow_path); |
| 4669 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4670 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4671 | Register length = length_loc.AsRegister<Register>(); |
| 4672 | if (index_loc.IsConstant()) { |
| 4673 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4674 | __ cmpl(length, Immediate(value)); |
| 4675 | } else { |
| 4676 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 4677 | } |
| 4678 | codegen_->AddSlowPath(slow_path); |
| 4679 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4680 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4681 | } |
| 4682 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4683 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 4684 | temp->SetLocations(nullptr); |
| 4685 | } |
| 4686 | |
| 4687 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 4688 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4689 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4690 | } |
| 4691 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4692 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4693 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4694 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4698 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4699 | } |
| 4700 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4701 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4702 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4703 | } |
| 4704 | |
| 4705 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4706 | HBasicBlock* block = instruction->GetBlock(); |
| 4707 | if (block->GetLoopInformation() != nullptr) { |
| 4708 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4709 | // The back edge will generate the suspend check. |
| 4710 | return; |
| 4711 | } |
| 4712 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4713 | // The goto will generate the suspend check. |
| 4714 | return; |
| 4715 | } |
| 4716 | GenerateSuspendCheck(instruction, nullptr); |
| 4717 | } |
| 4718 | |
| 4719 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4720 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4721 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4722 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 4723 | if (slow_path == nullptr) { |
| 4724 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 4725 | instruction->SetSlowPath(slow_path); |
| 4726 | codegen_->AddSlowPath(slow_path); |
| 4727 | if (successor != nullptr) { |
| 4728 | DCHECK(successor->IsLoopHeader()); |
| 4729 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4730 | } |
| 4731 | } else { |
| 4732 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4733 | } |
| 4734 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4735 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4736 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4737 | if (successor == nullptr) { |
| 4738 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4739 | __ Bind(slow_path->GetReturnLabel()); |
| 4740 | } else { |
| 4741 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4742 | __ jmp(slow_path->GetEntryLabel()); |
| 4743 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4744 | } |
| 4745 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4746 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 4747 | return codegen_->GetAssembler(); |
| 4748 | } |
| 4749 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4750 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4751 | ScratchRegisterScope ensure_scratch( |
| 4752 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4753 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4754 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4755 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4756 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4760 | ScratchRegisterScope ensure_scratch( |
| 4761 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4762 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4763 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4764 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4765 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 4766 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 4767 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4768 | } |
| 4769 | |
| 4770 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4771 | DCHECK_LT(index, moves_.size()); |
| 4772 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4773 | Location source = move->GetSource(); |
| 4774 | Location destination = move->GetDestination(); |
| 4775 | |
| 4776 | if (source.IsRegister()) { |
| 4777 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4778 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4779 | } else { |
| 4780 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4781 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4782 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4783 | } else if (source.IsFpuRegister()) { |
| 4784 | if (destination.IsFpuRegister()) { |
| 4785 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4786 | } else if (destination.IsStackSlot()) { |
| 4787 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4788 | } else { |
| 4789 | DCHECK(destination.IsDoubleStackSlot()); |
| 4790 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4791 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4792 | } else if (source.IsStackSlot()) { |
| 4793 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4794 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4795 | } else if (destination.IsFpuRegister()) { |
| 4796 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4797 | } else { |
| 4798 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4799 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4800 | } |
| 4801 | } else if (source.IsDoubleStackSlot()) { |
| 4802 | if (destination.IsFpuRegister()) { |
| 4803 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 4804 | } else { |
| 4805 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4806 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4807 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4808 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4809 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4810 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4811 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4812 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4813 | if (value == 0) { |
| 4814 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4815 | } else { |
| 4816 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 4817 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4818 | } else { |
| 4819 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4820 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4821 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4822 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4823 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4824 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4825 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4826 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4827 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4828 | if (value == 0) { |
| 4829 | // Easy handling of 0.0. |
| 4830 | __ xorps(dest, dest); |
| 4831 | } else { |
| 4832 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4833 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4834 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4835 | __ movl(temp, Immediate(value)); |
| 4836 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4837 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4838 | } else { |
| 4839 | DCHECK(destination.IsStackSlot()) << destination; |
| 4840 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 4841 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4842 | } else if (constant->IsLongConstant()) { |
| 4843 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4844 | int32_t low_value = Low32Bits(value); |
| 4845 | int32_t high_value = High32Bits(value); |
| 4846 | Immediate low(low_value); |
| 4847 | Immediate high(high_value); |
| 4848 | if (destination.IsDoubleStackSlot()) { |
| 4849 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4850 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4851 | } else { |
| 4852 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 4853 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 4854 | } |
| 4855 | } else { |
| 4856 | DCHECK(constant->IsDoubleConstant()); |
| 4857 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4858 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4859 | int32_t low_value = Low32Bits(value); |
| 4860 | int32_t high_value = High32Bits(value); |
| 4861 | Immediate low(low_value); |
| 4862 | Immediate high(high_value); |
| 4863 | if (destination.IsFpuRegister()) { |
| 4864 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4865 | if (value == 0) { |
| 4866 | // Easy handling of 0.0. |
| 4867 | __ xorpd(dest, dest); |
| 4868 | } else { |
| 4869 | __ pushl(high); |
| 4870 | __ pushl(low); |
| 4871 | __ movsd(dest, Address(ESP, 0)); |
| 4872 | __ addl(ESP, Immediate(8)); |
| 4873 | } |
| 4874 | } else { |
| 4875 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4876 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4877 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4878 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4879 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4880 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4881 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4882 | } |
| 4883 | } |
| 4884 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4885 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4886 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4887 | ScratchRegisterScope ensure_scratch( |
| 4888 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4889 | |
| 4890 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4891 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4892 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4893 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4894 | } |
| 4895 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4896 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4897 | ScratchRegisterScope ensure_scratch( |
| 4898 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4899 | |
| 4900 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4901 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4902 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4903 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4904 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4905 | } |
| 4906 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4907 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4908 | ScratchRegisterScope ensure_scratch1( |
| 4909 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4910 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4911 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4912 | ScratchRegisterScope ensure_scratch2( |
| 4913 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4914 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4915 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4916 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4917 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4918 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4919 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4920 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4924 | DCHECK_LT(index, moves_.size()); |
| 4925 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4926 | Location source = move->GetSource(); |
| 4927 | Location destination = move->GetDestination(); |
| 4928 | |
| 4929 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 4930 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 4931 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4932 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4933 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4934 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4935 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4936 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4937 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4938 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4939 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4940 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4941 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4942 | // Use XOR Swap algorithm to avoid a temporary. |
| 4943 | DCHECK_NE(source.reg(), destination.reg()); |
| 4944 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4945 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4946 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4947 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4948 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4949 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4950 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4951 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4952 | // Take advantage of the 16 bytes in the XMM register. |
| 4953 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4954 | Address stack(ESP, destination.GetStackIndex()); |
| 4955 | // Load the double into the high doubleword. |
| 4956 | __ movhpd(reg, stack); |
| 4957 | |
| 4958 | // Store the low double into the destination. |
| 4959 | __ movsd(stack, reg); |
| 4960 | |
| 4961 | // Move the high double to the low double. |
| 4962 | __ psrldq(reg, Immediate(8)); |
| 4963 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4964 | // Take advantage of the 16 bytes in the XMM register. |
| 4965 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4966 | Address stack(ESP, source.GetStackIndex()); |
| 4967 | // Load the double into the high doubleword. |
| 4968 | __ movhpd(reg, stack); |
| 4969 | |
| 4970 | // Store the low double into the destination. |
| 4971 | __ movsd(stack, reg); |
| 4972 | |
| 4973 | // Move the high double to the low double. |
| 4974 | __ psrldq(reg, Immediate(8)); |
| 4975 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4976 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4977 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4978 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4979 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4980 | } |
| 4981 | } |
| 4982 | |
| 4983 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4984 | __ pushl(static_cast<Register>(reg)); |
| 4985 | } |
| 4986 | |
| 4987 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4988 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4989 | } |
| 4990 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4991 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4992 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4993 | ? LocationSummary::kCallOnSlowPath |
| 4994 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4995 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4996 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4997 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4998 | locations->SetOut(Location::RequiresRegister()); |
| 4999 | } |
| 5000 | |
| 5001 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5002 | LocationSummary* locations = cls->GetLocations(); |
| 5003 | Register out = locations->Out().AsRegister<Register>(); |
| 5004 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5005 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5006 | DCHECK(!cls->CanCallRuntime()); |
| 5007 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 5008 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5009 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5010 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5011 | __ movl(out, Address( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5012 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5013 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5014 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5015 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5016 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5017 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 5018 | codegen_->AddSlowPath(slow_path); |
| 5019 | __ testl(out, out); |
| 5020 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5021 | if (cls->MustGenerateClinitCheck()) { |
| 5022 | GenerateClassInitializationCheck(slow_path, out); |
| 5023 | } else { |
| 5024 | __ Bind(slow_path->GetExitLabel()); |
| 5025 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 5030 | LocationSummary* locations = |
| 5031 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 5032 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5033 | if (check->HasUses()) { |
| 5034 | locations->SetOut(Location::SameAsFirstInput()); |
| 5035 | } |
| 5036 | } |
| 5037 | |
| 5038 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5039 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5040 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5041 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5042 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5043 | GenerateClassInitializationCheck(slow_path, |
| 5044 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5045 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5046 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5047 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5048 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5049 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 5050 | Immediate(mirror::Class::kStatusInitialized)); |
| 5051 | __ j(kLess, slow_path->GetEntryLabel()); |
| 5052 | __ Bind(slow_path->GetExitLabel()); |
| 5053 | // No need for memory fence, thanks to the X86 memory model. |
| 5054 | } |
| 5055 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5056 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 5057 | LocationSummary* locations = |
| 5058 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5059 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5060 | locations->SetOut(Location::RequiresRegister()); |
| 5061 | } |
| 5062 | |
| 5063 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5064 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5065 | codegen_->AddSlowPath(slow_path); |
| 5066 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5067 | LocationSummary* locations = load->GetLocations(); |
| 5068 | Register out = locations->Out().AsRegister<Register>(); |
| 5069 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 5070 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 5071 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5072 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 5073 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5074 | __ testl(out, out); |
| 5075 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5076 | __ Bind(slow_path->GetExitLabel()); |
| 5077 | } |
| 5078 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5079 | static Address GetExceptionTlsAddress() { |
| 5080 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 5081 | } |
| 5082 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5083 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 5084 | LocationSummary* locations = |
| 5085 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 5086 | locations->SetOut(Location::RequiresRegister()); |
| 5087 | } |
| 5088 | |
| 5089 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5090 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 5091 | } |
| 5092 | |
| 5093 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 5094 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 5095 | } |
| 5096 | |
| 5097 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 5098 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5099 | } |
| 5100 | |
| 5101 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5102 | LocationSummary* locations = |
| 5103 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5104 | InvokeRuntimeCallingConvention calling_convention; |
| 5105 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5106 | } |
| 5107 | |
| 5108 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5109 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5110 | instruction, |
| 5111 | instruction->GetDexPc(), |
| 5112 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5113 | } |
| 5114 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5115 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5116 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5117 | switch (instruction->GetTypeCheckKind()) { |
| 5118 | case TypeCheckKind::kExactCheck: |
| 5119 | case TypeCheckKind::kAbstractClassCheck: |
| 5120 | case TypeCheckKind::kClassHierarchyCheck: |
| 5121 | case TypeCheckKind::kArrayObjectCheck: |
| 5122 | call_kind = LocationSummary::kNoCall; |
| 5123 | break; |
| 5124 | case TypeCheckKind::kInterfaceCheck: |
| 5125 | call_kind = LocationSummary::kCall; |
| 5126 | break; |
| 5127 | case TypeCheckKind::kArrayCheck: |
| 5128 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5129 | break; |
| 5130 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5131 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5132 | if (call_kind != LocationSummary::kCall) { |
| 5133 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5134 | locations->SetInAt(1, Location::Any()); |
| 5135 | // Note that TypeCheckSlowPathX86 uses this register too. |
| 5136 | locations->SetOut(Location::RequiresRegister()); |
| 5137 | } else { |
| 5138 | InvokeRuntimeCallingConvention calling_convention; |
| 5139 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5140 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5141 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 5142 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5143 | } |
| 5144 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5145 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5146 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5147 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5148 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5149 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5150 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5151 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5152 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5153 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5154 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5155 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5156 | |
| 5157 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5158 | // Avoid null check if we know obj is not null. |
| 5159 | if (instruction->MustDoNullCheck()) { |
| 5160 | __ testl(obj, obj); |
| 5161 | __ j(kEqual, &zero); |
| 5162 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5163 | |
| 5164 | // In case of an interface check, we put the object class into the object register. |
| 5165 | // This is safe, as the register is caller-save, and the object must be in another |
| 5166 | // register if it survives the runtime call. |
| 5167 | Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) |
| 5168 | ? obj |
| 5169 | : out; |
| 5170 | __ movl(target, Address(obj, class_offset)); |
| 5171 | __ MaybeUnpoisonHeapReference(target); |
| 5172 | |
| 5173 | switch (instruction->GetTypeCheckKind()) { |
| 5174 | case TypeCheckKind::kExactCheck: { |
| 5175 | if (cls.IsRegister()) { |
| 5176 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5177 | } else { |
| 5178 | DCHECK(cls.IsStackSlot()) << cls; |
| 5179 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5180 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5181 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5182 | // Classes must be equal for the instanceof to succeed. |
| 5183 | __ j(kNotEqual, &zero); |
| 5184 | __ movl(out, Immediate(1)); |
| 5185 | __ jmp(&done); |
| 5186 | break; |
| 5187 | } |
| 5188 | case TypeCheckKind::kAbstractClassCheck: { |
| 5189 | // If the class is abstract, we eagerly fetch the super class of the |
| 5190 | // object to avoid doing a comparison we know will fail. |
| 5191 | NearLabel loop; |
| 5192 | __ Bind(&loop); |
| 5193 | __ movl(out, Address(out, super_offset)); |
| 5194 | __ MaybeUnpoisonHeapReference(out); |
| 5195 | __ testl(out, out); |
| 5196 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5197 | __ j(kEqual, &done); |
| 5198 | if (cls.IsRegister()) { |
| 5199 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5200 | } else { |
| 5201 | DCHECK(cls.IsStackSlot()) << cls; |
| 5202 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5203 | } |
| 5204 | __ j(kNotEqual, &loop); |
| 5205 | __ movl(out, Immediate(1)); |
| 5206 | if (zero.IsLinked()) { |
| 5207 | __ jmp(&done); |
| 5208 | } |
| 5209 | break; |
| 5210 | } |
| 5211 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5212 | // Walk over the class hierarchy to find a match. |
| 5213 | NearLabel loop, success; |
| 5214 | __ Bind(&loop); |
| 5215 | if (cls.IsRegister()) { |
| 5216 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5217 | } else { |
| 5218 | DCHECK(cls.IsStackSlot()) << cls; |
| 5219 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5220 | } |
| 5221 | __ j(kEqual, &success); |
| 5222 | __ movl(out, Address(out, super_offset)); |
| 5223 | __ MaybeUnpoisonHeapReference(out); |
| 5224 | __ testl(out, out); |
| 5225 | __ j(kNotEqual, &loop); |
| 5226 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5227 | __ jmp(&done); |
| 5228 | __ Bind(&success); |
| 5229 | __ movl(out, Immediate(1)); |
| 5230 | if (zero.IsLinked()) { |
| 5231 | __ jmp(&done); |
| 5232 | } |
| 5233 | break; |
| 5234 | } |
| 5235 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5236 | // Do an exact check. |
| 5237 | NearLabel exact_check; |
| 5238 | if (cls.IsRegister()) { |
| 5239 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5240 | } else { |
| 5241 | DCHECK(cls.IsStackSlot()) << cls; |
| 5242 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5243 | } |
| 5244 | __ j(kEqual, &exact_check); |
| 5245 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5246 | __ movl(out, Address(out, component_offset)); |
| 5247 | __ MaybeUnpoisonHeapReference(out); |
| 5248 | __ testl(out, out); |
| 5249 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5250 | __ j(kEqual, &done); |
| 5251 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5252 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5253 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5254 | __ movl(out, Immediate(1)); |
| 5255 | __ jmp(&done); |
| 5256 | break; |
| 5257 | } |
| 5258 | case TypeCheckKind::kArrayCheck: { |
| 5259 | if (cls.IsRegister()) { |
| 5260 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5261 | } else { |
| 5262 | DCHECK(cls.IsStackSlot()) << cls; |
| 5263 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5264 | } |
| 5265 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5266 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 5267 | instruction, /* is_fatal */ false); |
| 5268 | codegen_->AddSlowPath(slow_path); |
| 5269 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5270 | __ movl(out, Immediate(1)); |
| 5271 | if (zero.IsLinked()) { |
| 5272 | __ jmp(&done); |
| 5273 | } |
| 5274 | break; |
| 5275 | } |
| 5276 | |
| 5277 | case TypeCheckKind::kInterfaceCheck: |
| 5278 | default: { |
| 5279 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 5280 | instruction, |
| 5281 | instruction->GetDexPc(), |
| 5282 | nullptr); |
| 5283 | if (zero.IsLinked()) { |
| 5284 | __ jmp(&done); |
| 5285 | } |
| 5286 | break; |
| 5287 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5288 | } |
| 5289 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5290 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5291 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5292 | __ xorl(out, out); |
| 5293 | } |
| 5294 | |
| 5295 | if (done.IsLinked()) { |
| 5296 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5297 | } |
| 5298 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5299 | if (slow_path != nullptr) { |
| 5300 | __ Bind(slow_path->GetExitLabel()); |
| 5301 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5302 | } |
| 5303 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5304 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5305 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5306 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5307 | |
| 5308 | switch (instruction->GetTypeCheckKind()) { |
| 5309 | case TypeCheckKind::kExactCheck: |
| 5310 | case TypeCheckKind::kAbstractClassCheck: |
| 5311 | case TypeCheckKind::kClassHierarchyCheck: |
| 5312 | case TypeCheckKind::kArrayObjectCheck: |
| 5313 | call_kind = throws_into_catch |
| 5314 | ? LocationSummary::kCallOnSlowPath |
| 5315 | : LocationSummary::kNoCall; |
| 5316 | break; |
| 5317 | case TypeCheckKind::kInterfaceCheck: |
| 5318 | call_kind = LocationSummary::kCall; |
| 5319 | break; |
| 5320 | case TypeCheckKind::kArrayCheck: |
| 5321 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5322 | break; |
| 5323 | } |
| 5324 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5325 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5326 | instruction, call_kind); |
| 5327 | if (call_kind != LocationSummary::kCall) { |
| 5328 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5329 | locations->SetInAt(1, Location::Any()); |
| 5330 | // Note that TypeCheckSlowPathX86 uses this register too. |
| 5331 | locations->AddTemp(Location::RequiresRegister()); |
| 5332 | } else { |
| 5333 | InvokeRuntimeCallingConvention calling_convention; |
| 5334 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5335 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5336 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 5340 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5341 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5342 | Location cls = locations->InAt(1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5343 | Register temp = locations->WillCall() |
| 5344 | ? kNoRegister |
| 5345 | : locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 5346 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5347 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5348 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5349 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5350 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 5351 | SlowPathCode* slow_path = nullptr; |
| 5352 | |
| 5353 | if (!locations->WillCall()) { |
| 5354 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 5355 | instruction, !locations->CanCall()); |
| 5356 | codegen_->AddSlowPath(slow_path); |
| 5357 | } |
| 5358 | |
| 5359 | NearLabel done, abstract_entry; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5360 | // Avoid null check if we know obj is not null. |
| 5361 | if (instruction->MustDoNullCheck()) { |
| 5362 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5363 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5364 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5365 | |
| 5366 | if (locations->WillCall()) { |
| 5367 | __ movl(obj, Address(obj, class_offset)); |
| 5368 | __ MaybeUnpoisonHeapReference(obj); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5369 | } else { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5370 | __ movl(temp, Address(obj, class_offset)); |
| 5371 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5372 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5373 | |
| 5374 | switch (instruction->GetTypeCheckKind()) { |
| 5375 | case TypeCheckKind::kExactCheck: |
| 5376 | case TypeCheckKind::kArrayCheck: { |
| 5377 | if (cls.IsRegister()) { |
| 5378 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5379 | } else { |
| 5380 | DCHECK(cls.IsStackSlot()) << cls; |
| 5381 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5382 | } |
| 5383 | // Jump to slow path for throwing the exception or doing a |
| 5384 | // more involved array check. |
| 5385 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5386 | break; |
| 5387 | } |
| 5388 | case TypeCheckKind::kAbstractClassCheck: { |
| 5389 | // If the class is abstract, we eagerly fetch the super class of the |
| 5390 | // object to avoid doing a comparison we know will fail. |
| 5391 | NearLabel loop, success; |
| 5392 | __ Bind(&loop); |
| 5393 | __ movl(temp, Address(temp, super_offset)); |
| 5394 | __ MaybeUnpoisonHeapReference(temp); |
| 5395 | __ testl(temp, temp); |
| 5396 | // Jump to the slow path to throw the exception. |
| 5397 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5398 | if (cls.IsRegister()) { |
| 5399 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5400 | } else { |
| 5401 | DCHECK(cls.IsStackSlot()) << cls; |
| 5402 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5403 | } |
| 5404 | __ j(kNotEqual, &loop); |
| 5405 | break; |
| 5406 | } |
| 5407 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5408 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5409 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5410 | __ Bind(&loop); |
| 5411 | if (cls.IsRegister()) { |
| 5412 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5413 | } else { |
| 5414 | DCHECK(cls.IsStackSlot()) << cls; |
| 5415 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5416 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5417 | __ j(kEqual, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5418 | __ movl(temp, Address(temp, super_offset)); |
| 5419 | __ MaybeUnpoisonHeapReference(temp); |
| 5420 | __ testl(temp, temp); |
| 5421 | __ j(kNotEqual, &loop); |
| 5422 | // Jump to the slow path to throw the exception. |
| 5423 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5424 | break; |
| 5425 | } |
| 5426 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5427 | // Do an exact check. |
| 5428 | if (cls.IsRegister()) { |
| 5429 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5430 | } else { |
| 5431 | DCHECK(cls.IsStackSlot()) << cls; |
| 5432 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5433 | } |
| 5434 | __ j(kEqual, &done); |
| 5435 | // Otherwise, we need to check that the object's class is a non primitive array. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5436 | __ movl(temp, Address(temp, component_offset)); |
| 5437 | __ MaybeUnpoisonHeapReference(temp); |
| 5438 | __ testl(temp, temp); |
| 5439 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5440 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5441 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5442 | break; |
| 5443 | } |
| 5444 | case TypeCheckKind::kInterfaceCheck: |
| 5445 | default: |
| 5446 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 5447 | instruction, |
| 5448 | instruction->GetDexPc(), |
| 5449 | nullptr); |
| 5450 | break; |
| 5451 | } |
| 5452 | __ Bind(&done); |
| 5453 | |
| 5454 | if (slow_path != nullptr) { |
| 5455 | __ Bind(slow_path->GetExitLabel()); |
| 5456 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5457 | } |
| 5458 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5459 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5460 | LocationSummary* locations = |
| 5461 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5462 | InvokeRuntimeCallingConvention calling_convention; |
| 5463 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5464 | } |
| 5465 | |
| 5466 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5467 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5468 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5469 | instruction, |
| 5470 | instruction->GetDexPc(), |
| 5471 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5472 | } |
| 5473 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5474 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5475 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5476 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5477 | |
| 5478 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5479 | LocationSummary* locations = |
| 5480 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5481 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5482 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5483 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5484 | locations->SetInAt(1, Location::Any()); |
| 5485 | locations->SetOut(Location::SameAsFirstInput()); |
| 5486 | } |
| 5487 | |
| 5488 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 5489 | HandleBitwiseOperation(instruction); |
| 5490 | } |
| 5491 | |
| 5492 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 5493 | HandleBitwiseOperation(instruction); |
| 5494 | } |
| 5495 | |
| 5496 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 5497 | HandleBitwiseOperation(instruction); |
| 5498 | } |
| 5499 | |
| 5500 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5501 | LocationSummary* locations = instruction->GetLocations(); |
| 5502 | Location first = locations->InAt(0); |
| 5503 | Location second = locations->InAt(1); |
| 5504 | DCHECK(first.Equals(locations->Out())); |
| 5505 | |
| 5506 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5507 | if (second.IsRegister()) { |
| 5508 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5509 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5510 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5511 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5512 | } else { |
| 5513 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5514 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5515 | } |
| 5516 | } else if (second.IsConstant()) { |
| 5517 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5518 | __ andl(first.AsRegister<Register>(), |
| 5519 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5520 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5521 | __ orl(first.AsRegister<Register>(), |
| 5522 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5523 | } else { |
| 5524 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5525 | __ xorl(first.AsRegister<Register>(), |
| 5526 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5527 | } |
| 5528 | } else { |
| 5529 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5530 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5531 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5532 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5533 | } else { |
| 5534 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5535 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5536 | } |
| 5537 | } |
| 5538 | } else { |
| 5539 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5540 | if (second.IsRegisterPair()) { |
| 5541 | if (instruction->IsAnd()) { |
| 5542 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5543 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5544 | } else if (instruction->IsOr()) { |
| 5545 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5546 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5547 | } else { |
| 5548 | DCHECK(instruction->IsXor()); |
| 5549 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5550 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5551 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5552 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5553 | if (instruction->IsAnd()) { |
| 5554 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5555 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 5556 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5557 | } else if (instruction->IsOr()) { |
| 5558 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5559 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 5560 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5561 | } else { |
| 5562 | DCHECK(instruction->IsXor()); |
| 5563 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5564 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 5565 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5566 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5567 | } else { |
| 5568 | DCHECK(second.IsConstant()) << second; |
| 5569 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5570 | int32_t low_value = Low32Bits(value); |
| 5571 | int32_t high_value = High32Bits(value); |
| 5572 | Immediate low(low_value); |
| 5573 | Immediate high(high_value); |
| 5574 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5575 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5576 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5577 | if (low_value == 0) { |
| 5578 | __ xorl(first_low, first_low); |
| 5579 | } else if (low_value != -1) { |
| 5580 | __ andl(first_low, low); |
| 5581 | } |
| 5582 | if (high_value == 0) { |
| 5583 | __ xorl(first_high, first_high); |
| 5584 | } else if (high_value != -1) { |
| 5585 | __ andl(first_high, high); |
| 5586 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5587 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5588 | if (low_value != 0) { |
| 5589 | __ orl(first_low, low); |
| 5590 | } |
| 5591 | if (high_value != 0) { |
| 5592 | __ orl(first_high, high); |
| 5593 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5594 | } else { |
| 5595 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5596 | if (low_value != 0) { |
| 5597 | __ xorl(first_low, low); |
| 5598 | } |
| 5599 | if (high_value != 0) { |
| 5600 | __ xorl(first_high, high); |
| 5601 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5602 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5603 | } |
| 5604 | } |
| 5605 | } |
| 5606 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5607 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 5608 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5609 | UNUSED(instruction); |
| 5610 | LOG(FATAL) << "Unreachable"; |
| 5611 | } |
| 5612 | |
| 5613 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 5614 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5615 | UNUSED(instruction); |
| 5616 | LOG(FATAL) << "Unreachable"; |
| 5617 | } |
| 5618 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5619 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 5620 | DCHECK(codegen_->IsBaseline()); |
| 5621 | LocationSummary* locations = |
| 5622 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5623 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5624 | } |
| 5625 | |
| 5626 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5627 | DCHECK(codegen_->IsBaseline()); |
| 5628 | // Will be generated at use site. |
| 5629 | } |
| 5630 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5631 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5632 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5633 | LocationSummary* locations = |
| 5634 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5635 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5636 | } |
| 5637 | |
| 5638 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5639 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 5640 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 5641 | LocationSummary* locations = switch_instr->GetLocations(); |
| 5642 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 5643 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5644 | |
| 5645 | // Create a series of compare/jumps. |
| 5646 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 5647 | for (int i = 0; i < num_entries; i++) { |
| 5648 | int32_t case_value = lower_bound + i; |
| 5649 | if (case_value == 0) { |
| 5650 | __ testl(value_reg, value_reg); |
| 5651 | } else { |
| 5652 | __ cmpl(value_reg, Immediate(case_value)); |
| 5653 | } |
| 5654 | __ j(kEqual, codegen_->GetLabelOf(successors.at(i))); |
| 5655 | } |
| 5656 | |
| 5657 | // And the default for any other value. |
| 5658 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5659 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 5660 | } |
| 5661 | } |
| 5662 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5663 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 5664 | HX86ComputeBaseMethodAddress* insn) { |
| 5665 | LocationSummary* locations = |
| 5666 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5667 | locations->SetOut(Location::RequiresRegister()); |
| 5668 | } |
| 5669 | |
| 5670 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 5671 | HX86ComputeBaseMethodAddress* insn) { |
| 5672 | LocationSummary* locations = insn->GetLocations(); |
| 5673 | Register reg = locations->Out().AsRegister<Register>(); |
| 5674 | |
| 5675 | // Generate call to next instruction. |
| 5676 | Label next_instruction; |
| 5677 | __ call(&next_instruction); |
| 5678 | __ Bind(&next_instruction); |
| 5679 | |
| 5680 | // Remember this offset for later use with constant area. |
| 5681 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 5682 | |
| 5683 | // Grab the return address off the stack. |
| 5684 | __ popl(reg); |
| 5685 | } |
| 5686 | |
| 5687 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 5688 | HX86LoadFromConstantTable* insn) { |
| 5689 | LocationSummary* locations = |
| 5690 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5691 | |
| 5692 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5693 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 5694 | |
| 5695 | // If we don't need to be materialized, we only need the inputs to be set. |
| 5696 | if (!insn->NeedsMaterialization()) { |
| 5697 | return; |
| 5698 | } |
| 5699 | |
| 5700 | switch (insn->GetType()) { |
| 5701 | case Primitive::kPrimFloat: |
| 5702 | case Primitive::kPrimDouble: |
| 5703 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5704 | break; |
| 5705 | |
| 5706 | case Primitive::kPrimInt: |
| 5707 | locations->SetOut(Location::RequiresRegister()); |
| 5708 | break; |
| 5709 | |
| 5710 | default: |
| 5711 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 5716 | if (!insn->NeedsMaterialization()) { |
| 5717 | return; |
| 5718 | } |
| 5719 | |
| 5720 | LocationSummary* locations = insn->GetLocations(); |
| 5721 | Location out = locations->Out(); |
| 5722 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 5723 | HConstant *value = insn->GetConstant(); |
| 5724 | |
| 5725 | switch (insn->GetType()) { |
| 5726 | case Primitive::kPrimFloat: |
| 5727 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 5728 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 5729 | break; |
| 5730 | |
| 5731 | case Primitive::kPrimDouble: |
| 5732 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 5733 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 5734 | break; |
| 5735 | |
| 5736 | case Primitive::kPrimInt: |
| 5737 | __ movl(out.AsRegister<Register>(), |
| 5738 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 5739 | break; |
| 5740 | |
| 5741 | default: |
| 5742 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5743 | } |
| 5744 | } |
| 5745 | |
| 5746 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 5747 | // Generate the constant area if needed. |
| 5748 | X86Assembler* assembler = GetAssembler(); |
| 5749 | if (!assembler->IsConstantAreaEmpty()) { |
| 5750 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 5751 | // byte values. |
| 5752 | assembler->Align(4, 0); |
| 5753 | constant_area_start_ = assembler->CodeSize(); |
| 5754 | assembler->AddConstantArea(); |
| 5755 | } |
| 5756 | |
| 5757 | // And finish up. |
| 5758 | CodeGenerator::Finalize(allocator); |
| 5759 | } |
| 5760 | |
| 5761 | /** |
| 5762 | * Class to handle late fixup of offsets into constant area. |
| 5763 | */ |
Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 5764 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5765 | public: |
| 5766 | RIPFixup(const CodeGeneratorX86& codegen, int offset) |
| 5767 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 5768 | |
| 5769 | private: |
| 5770 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5771 | // Patch the correct offset for the instruction. The place to patch is the |
| 5772 | // last 4 bytes of the instruction. |
| 5773 | // The value to patch is the distance from the offset in the constant area |
| 5774 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| 5775 | int32_t constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 5776 | int32_t relative_position = constant_offset - codegen_.GetMethodAddressOffset();; |
| 5777 | |
| 5778 | // Patch in the right value. |
| 5779 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5780 | } |
| 5781 | |
| 5782 | const CodeGeneratorX86& codegen_; |
| 5783 | |
| 5784 | // Location in constant area that the fixup refers to. |
| 5785 | int offset_into_constant_area_; |
| 5786 | }; |
| 5787 | |
| 5788 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 5789 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5790 | return Address(reg, kDummy32BitOffset, fixup); |
| 5791 | } |
| 5792 | |
| 5793 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 5794 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5795 | return Address(reg, kDummy32BitOffset, fixup); |
| 5796 | } |
| 5797 | |
| 5798 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 5799 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5800 | return Address(reg, kDummy32BitOffset, fixup); |
| 5801 | } |
| 5802 | |
| 5803 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 5804 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5805 | return Address(reg, kDummy32BitOffset, fixup); |
| 5806 | } |
| 5807 | |
| 5808 | /** |
| 5809 | * Finds instructions that need the constant area base as an input. |
| 5810 | */ |
| 5811 | class ConstantHandlerVisitor : public HGraphVisitor { |
| 5812 | public: |
| 5813 | explicit ConstantHandlerVisitor(HGraph* graph) : HGraphVisitor(graph), base_(nullptr) {} |
| 5814 | |
| 5815 | private: |
| 5816 | void VisitAdd(HAdd* add) OVERRIDE { |
| 5817 | BinaryFP(add); |
| 5818 | } |
| 5819 | |
| 5820 | void VisitSub(HSub* sub) OVERRIDE { |
| 5821 | BinaryFP(sub); |
| 5822 | } |
| 5823 | |
| 5824 | void VisitMul(HMul* mul) OVERRIDE { |
| 5825 | BinaryFP(mul); |
| 5826 | } |
| 5827 | |
| 5828 | void VisitDiv(HDiv* div) OVERRIDE { |
| 5829 | BinaryFP(div); |
| 5830 | } |
| 5831 | |
| 5832 | void VisitReturn(HReturn* ret) OVERRIDE { |
| 5833 | HConstant* value = ret->InputAt(0)->AsConstant(); |
| 5834 | if ((value != nullptr && Primitive::IsFloatingPointType(value->GetType()))) { |
| 5835 | ReplaceInput(ret, value, 0, true); |
| 5836 | } |
| 5837 | } |
| 5838 | |
| 5839 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE { |
| 5840 | HandleInvoke(invoke); |
| 5841 | } |
| 5842 | |
| 5843 | void VisitInvokeVirtual(HInvokeVirtual* invoke) OVERRIDE { |
| 5844 | HandleInvoke(invoke); |
| 5845 | } |
| 5846 | |
| 5847 | void VisitInvokeInterface(HInvokeInterface* invoke) OVERRIDE { |
| 5848 | HandleInvoke(invoke); |
| 5849 | } |
| 5850 | |
| 5851 | void BinaryFP(HBinaryOperation* bin) { |
| 5852 | HConstant* rhs = bin->InputAt(1)->AsConstant(); |
| 5853 | if (rhs != nullptr && Primitive::IsFloatingPointType(bin->GetResultType())) { |
| 5854 | ReplaceInput(bin, rhs, 1, false); |
| 5855 | } |
| 5856 | } |
| 5857 | |
| 5858 | void InitializeConstantAreaPointer(HInstruction* user) { |
| 5859 | // Ensure we only initialize the pointer once. |
| 5860 | if (base_ != nullptr) { |
| 5861 | return; |
| 5862 | } |
| 5863 | |
| 5864 | HGraph* graph = GetGraph(); |
| 5865 | HBasicBlock* entry = graph->GetEntryBlock(); |
| 5866 | base_ = new (graph->GetArena()) HX86ComputeBaseMethodAddress(); |
| 5867 | HInstruction* insert_pos = (user->GetBlock() == entry) ? user : entry->GetLastInstruction(); |
| 5868 | entry->InsertInstructionBefore(base_, insert_pos); |
| 5869 | DCHECK(base_ != nullptr); |
| 5870 | } |
| 5871 | |
| 5872 | void ReplaceInput(HInstruction* insn, HConstant* value, int input_index, bool materialize) { |
| 5873 | InitializeConstantAreaPointer(insn); |
| 5874 | HGraph* graph = GetGraph(); |
| 5875 | HBasicBlock* block = insn->GetBlock(); |
| 5876 | HX86LoadFromConstantTable* load_constant = |
| 5877 | new (graph->GetArena()) HX86LoadFromConstantTable(base_, value, materialize); |
| 5878 | block->InsertInstructionBefore(load_constant, insn); |
| 5879 | insn->ReplaceInput(load_constant, input_index); |
| 5880 | } |
| 5881 | |
| 5882 | void HandleInvoke(HInvoke* invoke) { |
| 5883 | // Ensure that we can load FP arguments from the constant area. |
| 5884 | for (size_t i = 0, e = invoke->InputCount(); i < e; i++) { |
| 5885 | HConstant* input = invoke->InputAt(i)->AsConstant(); |
| 5886 | if (input != nullptr && Primitive::IsFloatingPointType(input->GetType())) { |
| 5887 | ReplaceInput(invoke, input, i, true); |
| 5888 | } |
| 5889 | } |
| 5890 | } |
| 5891 | |
| 5892 | // The generated HX86ComputeBaseMethodAddress in the entry block needed as an |
| 5893 | // input to the HX86LoadFromConstantTable instructions. |
| 5894 | HX86ComputeBaseMethodAddress* base_; |
| 5895 | }; |
| 5896 | |
| 5897 | void ConstantAreaFixups::Run() { |
| 5898 | ConstantHandlerVisitor visitor(graph_); |
| 5899 | visitor.VisitInsertionOrder(); |
| 5900 | } |
| 5901 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5902 | // TODO: target as memory. |
| 5903 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 5904 | if (!target.IsValid()) { |
| 5905 | DCHECK(type == Primitive::kPrimVoid); |
| 5906 | return; |
| 5907 | } |
| 5908 | |
| 5909 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 5910 | |
| 5911 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 5912 | if (target.Equals(return_loc)) { |
| 5913 | return; |
| 5914 | } |
| 5915 | |
| 5916 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 5917 | // with the else branch. |
| 5918 | if (type == Primitive::kPrimLong) { |
| 5919 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5920 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 5921 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 5922 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5923 | } else { |
| 5924 | // Let the parallel move resolver take care of all of this. |
| 5925 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5926 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 5927 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5928 | } |
| 5929 | } |
| 5930 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5931 | #undef __ |
| 5932 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5933 | } // namespace x86 |
| 5934 | } // namespace art |