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), |
| 523 | method_patches_(graph->GetArena()->Adapter()), |
| 524 | relative_call_patches_(graph->GetArena()->Adapter()) { |
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()) { |
| 830 | LOG(FATAL) << "Unimplemented"; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 831 | } else { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 832 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 833 | DCHECK(source.IsDoubleStackSlot()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 834 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); |
| 835 | __ movl(destination.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 836 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); |
| 837 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 838 | } else if (destination.IsFpuRegister()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 839 | if (source.IsFpuRegister()) { |
| 840 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 841 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 842 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 843 | } else { |
| 844 | LOG(FATAL) << "Unimplemented"; |
| 845 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 846 | } else { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 847 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 848 | if (source.IsRegisterPair()) { |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 849 | // No conflict possible, so just do the moves. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 850 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 851 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 852 | source.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 853 | } else if (source.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 854 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 855 | } else if (source.IsConstant()) { |
| 856 | HConstant* constant = source.GetConstant(); |
| 857 | int64_t value; |
| 858 | if (constant->IsLongConstant()) { |
| 859 | value = constant->AsLongConstant()->GetValue(); |
| 860 | } else { |
| 861 | DCHECK(constant->IsDoubleConstant()); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 862 | value = bit_cast<int64_t, double>(constant->AsDoubleConstant()->GetValue()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 863 | } |
| 864 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); |
| 865 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value))); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 866 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 867 | DCHECK(source.IsDoubleStackSlot()) << source; |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 868 | EmitParallelMoves( |
| 869 | Location::StackSlot(source.GetStackIndex()), |
| 870 | Location::StackSlot(destination.GetStackIndex()), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 871 | Primitive::kPrimInt, |
Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 872 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 873 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), |
| 874 | Primitive::kPrimInt); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | } |
| 878 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 879 | void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 880 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 881 | if (instruction->IsCurrentMethod()) { |
| 882 | Move32(location, Location::StackSlot(kCurrentMethodStackOffset)); |
| 883 | } else if (locations != nullptr && locations->Out().Equals(location)) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 884 | return; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 885 | } else if (locations != nullptr && locations->Out().IsConstant()) { |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 886 | HConstant* const_to_move = locations->Out().GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 887 | if (const_to_move->IsIntConstant() || const_to_move->IsNullConstant()) { |
| 888 | Immediate imm(GetInt32ValueOf(const_to_move)); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 889 | if (location.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 890 | __ movl(location.AsRegister<Register>(), imm); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 891 | } else if (location.IsStackSlot()) { |
| 892 | __ movl(Address(ESP, location.GetStackIndex()), imm); |
| 893 | } else { |
| 894 | DCHECK(location.IsConstant()); |
| 895 | DCHECK_EQ(location.GetConstant(), const_to_move); |
| 896 | } |
| 897 | } else if (const_to_move->IsLongConstant()) { |
| 898 | int64_t value = const_to_move->AsLongConstant()->GetValue(); |
| 899 | if (location.IsRegisterPair()) { |
| 900 | __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 901 | __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
| 902 | } else if (location.IsDoubleStackSlot()) { |
| 903 | __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value))); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 904 | __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), |
| 905 | Immediate(High32Bits(value))); |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 906 | } else { |
| 907 | DCHECK(location.IsConstant()); |
| 908 | DCHECK_EQ(location.GetConstant(), instruction); |
| 909 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 910 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 911 | } else if (instruction->IsTemporary()) { |
| 912 | Location temp_location = GetTemporaryLocation(instruction->AsTemporary()); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 913 | if (temp_location.IsStackSlot()) { |
| 914 | Move32(location, temp_location); |
| 915 | } else { |
| 916 | DCHECK(temp_location.IsDoubleStackSlot()); |
| 917 | Move64(location, temp_location); |
| 918 | } |
Roland Levillain | 476df55 | 2014-10-09 17:51:36 +0100 | [diff] [blame] | 919 | } else if (instruction->IsLoadLocal()) { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 920 | int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 921 | switch (instruction->GetType()) { |
| 922 | case Primitive::kPrimBoolean: |
| 923 | case Primitive::kPrimByte: |
| 924 | case Primitive::kPrimChar: |
| 925 | case Primitive::kPrimShort: |
| 926 | case Primitive::kPrimInt: |
| 927 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 928 | case Primitive::kPrimFloat: |
| 929 | Move32(location, Location::StackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 930 | break; |
| 931 | |
| 932 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 933 | case Primitive::kPrimDouble: |
| 934 | Move64(location, Location::DoubleStackSlot(slot)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 935 | break; |
| 936 | |
| 937 | default: |
| 938 | LOG(FATAL) << "Unimplemented local type " << instruction->GetType(); |
| 939 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 940 | } else { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 941 | DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 942 | switch (instruction->GetType()) { |
| 943 | case Primitive::kPrimBoolean: |
| 944 | case Primitive::kPrimByte: |
| 945 | case Primitive::kPrimChar: |
| 946 | case Primitive::kPrimShort: |
| 947 | case Primitive::kPrimInt: |
| 948 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 949 | case Primitive::kPrimFloat: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 950 | Move32(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 951 | break; |
| 952 | |
| 953 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 954 | case Primitive::kPrimDouble: |
Calin Juravle | a21f598 | 2014-11-13 15:53:04 +0000 | [diff] [blame] | 955 | Move64(location, locations->Out()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 956 | break; |
| 957 | |
| 958 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 959 | LOG(FATAL) << "Unexpected type " << instruction->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 960 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 964 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { |
| 965 | DCHECK(location.IsRegister()); |
| 966 | __ movl(location.AsRegister<Register>(), Immediate(value)); |
| 967 | } |
| 968 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 969 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 970 | DCHECK(!successor->IsExitBlock()); |
| 971 | |
| 972 | HBasicBlock* block = got->GetBlock(); |
| 973 | HInstruction* previous = got->GetPrevious(); |
| 974 | |
| 975 | HLoopInformation* info = block->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 976 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 977 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); |
| 978 | return; |
| 979 | } |
| 980 | |
| 981 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { |
| 982 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); |
| 983 | } |
| 984 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 985 | __ jmp(codegen_->GetLabelOf(successor)); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 989 | void LocationsBuilderX86::VisitGoto(HGoto* got) { |
| 990 | got->SetLocations(nullptr); |
| 991 | } |
| 992 | |
| 993 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { |
| 994 | HandleGoto(got, got->GetSuccessor()); |
| 995 | } |
| 996 | |
| 997 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 998 | try_boundary->SetLocations(nullptr); |
| 999 | } |
| 1000 | |
| 1001 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { |
| 1002 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); |
| 1003 | if (!successor->IsExitBlock()) { |
| 1004 | HandleGoto(try_boundary, successor); |
| 1005 | } |
| 1006 | } |
| 1007 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1008 | void LocationsBuilderX86::VisitExit(HExit* exit) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1009 | exit->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1012 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1013 | UNUSED(exit); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1016 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, |
| 1017 | Label* true_label, |
| 1018 | Label* false_label) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1019 | if (cond->IsFPConditionTrueIfNaN()) { |
| 1020 | __ j(kUnordered, true_label); |
| 1021 | } else if (cond->IsFPConditionFalseIfNaN()) { |
| 1022 | __ j(kUnordered, false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1023 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1024 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, |
| 1028 | Label* true_label, |
| 1029 | Label* false_label) { |
| 1030 | LocationSummary* locations = cond->GetLocations(); |
| 1031 | Location left = locations->InAt(0); |
| 1032 | Location right = locations->InAt(1); |
| 1033 | IfCondition if_cond = cond->GetCondition(); |
| 1034 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1035 | Register left_high = left.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1036 | Register left_low = left.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1037 | IfCondition true_high_cond = if_cond; |
| 1038 | IfCondition false_high_cond = cond->GetOppositeCondition(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1039 | Condition final_condition = X86UnsignedOrFPCondition(if_cond); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1040 | |
| 1041 | // Set the conditions for the test, remembering that == needs to be |
| 1042 | // decided using the low words. |
| 1043 | switch (if_cond) { |
| 1044 | case kCondEQ: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1045 | case kCondNE: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1046 | // Nothing to do. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1047 | break; |
| 1048 | case kCondLT: |
| 1049 | false_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1050 | break; |
| 1051 | case kCondLE: |
| 1052 | true_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1053 | break; |
| 1054 | case kCondGT: |
| 1055 | false_high_cond = kCondLT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1056 | break; |
| 1057 | case kCondGE: |
| 1058 | true_high_cond = kCondGT; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1059 | break; |
| 1060 | } |
| 1061 | |
| 1062 | if (right.IsConstant()) { |
| 1063 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1064 | int32_t val_high = High32Bits(value); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1065 | int32_t val_low = Low32Bits(value); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1066 | |
| 1067 | if (val_high == 0) { |
| 1068 | __ testl(left_high, left_high); |
| 1069 | } else { |
| 1070 | __ cmpl(left_high, Immediate(val_high)); |
| 1071 | } |
| 1072 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1073 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1074 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1075 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1076 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1077 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1078 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1079 | } |
| 1080 | // Must be equal high, so compare the lows. |
| 1081 | if (val_low == 0) { |
| 1082 | __ testl(left_low, left_low); |
| 1083 | } else { |
| 1084 | __ cmpl(left_low, Immediate(val_low)); |
| 1085 | } |
| 1086 | } else { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1087 | Register right_high = right.AsRegisterPairHigh<Register>(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1088 | Register right_low = right.AsRegisterPairLow<Register>(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1089 | |
| 1090 | __ cmpl(left_high, right_high); |
| 1091 | if (if_cond == kCondNE) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1092 | __ j(X86SignedCondition(true_high_cond), true_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1093 | } else if (if_cond == kCondEQ) { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1094 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1095 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1096 | __ j(X86SignedCondition(true_high_cond), true_label); |
| 1097 | __ j(X86SignedCondition(false_high_cond), false_label); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1098 | } |
| 1099 | // Must be equal high, so compare the lows. |
| 1100 | __ cmpl(left_low, right_low); |
| 1101 | } |
| 1102 | // The last comparison might be unsigned. |
| 1103 | __ j(final_condition, true_label); |
| 1104 | } |
| 1105 | |
| 1106 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HIf* if_instr, |
| 1107 | HCondition* condition, |
| 1108 | Label* true_target, |
| 1109 | Label* false_target, |
| 1110 | Label* always_true_target) { |
| 1111 | LocationSummary* locations = condition->GetLocations(); |
| 1112 | Location left = locations->InAt(0); |
| 1113 | Location right = locations->InAt(1); |
| 1114 | |
| 1115 | // We don't want true_target as a nullptr. |
| 1116 | if (true_target == nullptr) { |
| 1117 | true_target = always_true_target; |
| 1118 | } |
| 1119 | bool falls_through = (false_target == nullptr); |
| 1120 | |
| 1121 | // FP compares don't like null false_targets. |
| 1122 | if (false_target == nullptr) { |
| 1123 | false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1124 | } |
| 1125 | |
| 1126 | Primitive::Type type = condition->InputAt(0)->GetType(); |
| 1127 | switch (type) { |
| 1128 | case Primitive::kPrimLong: |
| 1129 | GenerateLongComparesAndJumps(condition, true_target, false_target); |
| 1130 | break; |
| 1131 | case Primitive::kPrimFloat: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1132 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1133 | GenerateFPJumps(condition, true_target, false_target); |
| 1134 | break; |
| 1135 | case Primitive::kPrimDouble: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1136 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
| 1137 | GenerateFPJumps(condition, true_target, false_target); |
| 1138 | break; |
| 1139 | default: |
| 1140 | LOG(FATAL) << "Unexpected compare type " << type; |
| 1141 | } |
| 1142 | |
| 1143 | if (!falls_through) { |
| 1144 | __ jmp(false_target); |
| 1145 | } |
| 1146 | } |
| 1147 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1148 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, |
| 1149 | Label* true_target, |
| 1150 | Label* false_target, |
| 1151 | Label* always_true_target) { |
| 1152 | HInstruction* cond = instruction->InputAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1153 | if (cond->IsIntConstant()) { |
| 1154 | // Constant condition, statically compared against 1. |
| 1155 | int32_t cond_value = cond->AsIntConstant()->GetValue(); |
| 1156 | if (cond_value == 1) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1157 | if (always_true_target != nullptr) { |
| 1158 | __ jmp(always_true_target); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1159 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1160 | return; |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1161 | } else { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1162 | DCHECK_EQ(cond_value, 0); |
| 1163 | } |
| 1164 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1165 | bool is_materialized = |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1166 | !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization(); |
| 1167 | // Moves do not affect the eflags register, so if the condition is |
| 1168 | // evaluated just before the if, we don't need to evaluate it |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1169 | // again. We can't use the eflags on long/FP conditions if they are |
| 1170 | // materialized due to the complex branching. |
| 1171 | Primitive::Type type = cond->IsCondition() ? cond->InputAt(0)->GetType() : Primitive::kPrimInt; |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1172 | bool eflags_set = cond->IsCondition() |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1173 | && cond->AsCondition()->IsBeforeWhenDisregardMoves(instruction) |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1174 | && (type != Primitive::kPrimLong && !Primitive::IsFloatingPointType(type)); |
| 1175 | if (is_materialized) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1176 | if (!eflags_set) { |
| 1177 | // Materialized condition, compare against 0. |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1178 | Location lhs = instruction->GetLocations()->InAt(0); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1179 | if (lhs.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1180 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1181 | } else { |
| 1182 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); |
| 1183 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1184 | __ j(kNotEqual, true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1185 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1186 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1187 | } |
| 1188 | } else { |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1189 | // Condition has not been materialized, use its inputs as the |
| 1190 | // comparison and its condition as the branch condition. |
| 1191 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1192 | // Is this a long or FP comparison that has been folded into the HCondition? |
| 1193 | if (type == Primitive::kPrimLong || Primitive::IsFloatingPointType(type)) { |
| 1194 | // Generate the comparison directly. |
| 1195 | GenerateCompareTestAndBranch(instruction->AsIf(), |
| 1196 | cond->AsCondition(), |
| 1197 | true_target, |
| 1198 | false_target, |
| 1199 | always_true_target); |
| 1200 | return; |
| 1201 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1202 | |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1203 | Location lhs = cond->GetLocations()->InAt(0); |
| 1204 | Location rhs = cond->GetLocations()->InAt(1); |
| 1205 | // LHS is guaranteed to be in a register (see |
| 1206 | // LocationsBuilderX86::VisitCondition). |
| 1207 | if (rhs.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1208 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1209 | } else if (rhs.IsConstant()) { |
Calin Juravle | b330664 | 2015-04-20 18:30:42 +0100 | [diff] [blame] | 1210 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 1211 | if (constant == 0) { |
| 1212 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1213 | } else { |
| 1214 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1215 | } |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1216 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1217 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1218 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1219 | __ j(X86SignedCondition(cond->AsCondition()->GetCondition()), true_target); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1220 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1221 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1222 | if (false_target != nullptr) { |
| 1223 | __ jmp(false_target); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1224 | } |
| 1225 | } |
| 1226 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1227 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { |
| 1228 | LocationSummary* locations = |
| 1229 | new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall); |
| 1230 | HInstruction* cond = if_instr->InputAt(0); |
| 1231 | if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) { |
| 1232 | locations->SetInAt(0, Location::Any()); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { |
| 1237 | Label* true_target = codegen_->GetLabelOf(if_instr->IfTrueSuccessor()); |
| 1238 | Label* false_target = codegen_->GetLabelOf(if_instr->IfFalseSuccessor()); |
| 1239 | Label* always_true_target = true_target; |
| 1240 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1241 | if_instr->IfTrueSuccessor())) { |
| 1242 | always_true_target = nullptr; |
| 1243 | } |
| 1244 | if (codegen_->GoesToNextBlock(if_instr->GetBlock(), |
| 1245 | if_instr->IfFalseSuccessor())) { |
| 1246 | false_target = nullptr; |
| 1247 | } |
| 1248 | GenerateTestAndBranch(if_instr, true_target, false_target, always_true_target); |
| 1249 | } |
| 1250 | |
| 1251 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
| 1252 | LocationSummary* locations = new (GetGraph()->GetArena()) |
| 1253 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); |
| 1254 | HInstruction* cond = deoptimize->InputAt(0); |
| 1255 | DCHECK(cond->IsCondition()); |
| 1256 | if (cond->AsCondition()->NeedsMaterialization()) { |
| 1257 | locations->SetInAt(0, Location::Any()); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1262 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1263 | DeoptimizationSlowPathX86(deoptimize); |
| 1264 | codegen_->AddSlowPath(slow_path); |
| 1265 | Label* slow_path_entry = slow_path->GetEntryLabel(); |
| 1266 | GenerateTestAndBranch(deoptimize, slow_path_entry, nullptr, slow_path_entry); |
| 1267 | } |
| 1268 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1269 | void LocationsBuilderX86::VisitLocal(HLocal* local) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1270 | local->SetLocations(nullptr); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1273 | void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) { |
| 1274 | DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock()); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1277 | void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1278 | local->SetLocations(nullptr); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1281 | void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) { |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1282 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1283 | UNUSED(load); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1286 | void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1287 | LocationSummary* locations = |
| 1288 | new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1289 | switch (store->InputAt(1)->GetType()) { |
| 1290 | case Primitive::kPrimBoolean: |
| 1291 | case Primitive::kPrimByte: |
| 1292 | case Primitive::kPrimChar: |
| 1293 | case Primitive::kPrimShort: |
| 1294 | case Primitive::kPrimInt: |
| 1295 | case Primitive::kPrimNot: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1296 | case Primitive::kPrimFloat: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1297 | locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1298 | break; |
| 1299 | |
| 1300 | case Primitive::kPrimLong: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1301 | case Primitive::kPrimDouble: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1302 | locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal()))); |
| 1303 | break; |
| 1304 | |
| 1305 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1306 | LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1307 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1310 | void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1311 | UNUSED(store); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1314 | void LocationsBuilderX86::VisitCondition(HCondition* cond) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1315 | LocationSummary* locations = |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1316 | new (GetGraph()->GetArena()) LocationSummary(cond, LocationSummary::kNoCall); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1317 | // Handle the long/FP comparisons made in instruction simplification. |
| 1318 | switch (cond->InputAt(0)->GetType()) { |
| 1319 | case Primitive::kPrimLong: { |
| 1320 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1321 | locations->SetInAt(1, Location::RegisterOrConstant(cond->InputAt(1))); |
| 1322 | if (cond->NeedsMaterialization()) { |
| 1323 | locations->SetOut(Location::RequiresRegister()); |
| 1324 | } |
| 1325 | break; |
| 1326 | } |
| 1327 | case Primitive::kPrimFloat: |
| 1328 | case Primitive::kPrimDouble: { |
| 1329 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1330 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1331 | if (cond->NeedsMaterialization()) { |
| 1332 | locations->SetOut(Location::RequiresRegister()); |
| 1333 | } |
| 1334 | break; |
| 1335 | } |
| 1336 | default: |
| 1337 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1338 | locations->SetInAt(1, Location::Any()); |
| 1339 | if (cond->NeedsMaterialization()) { |
| 1340 | // We need a byte register. |
| 1341 | locations->SetOut(Location::RegisterLocation(ECX)); |
| 1342 | } |
| 1343 | break; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1344 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Roland Levillain | 0d37cd0 | 2015-05-27 16:39:19 +0100 | [diff] [blame] | 1347 | void InstructionCodeGeneratorX86::VisitCondition(HCondition* cond) { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1348 | if (!cond->NeedsMaterialization()) { |
| 1349 | return; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1350 | } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1351 | |
| 1352 | LocationSummary* locations = cond->GetLocations(); |
| 1353 | Location lhs = locations->InAt(0); |
| 1354 | Location rhs = locations->InAt(1); |
| 1355 | Register reg = locations->Out().AsRegister<Register>(); |
| 1356 | Label true_label, false_label; |
| 1357 | |
| 1358 | switch (cond->InputAt(0)->GetType()) { |
| 1359 | default: { |
| 1360 | // Integer case. |
| 1361 | |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1362 | // Clear output register: setb only sets the low byte. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1363 | __ xorl(reg, reg); |
| 1364 | |
| 1365 | if (rhs.IsRegister()) { |
| 1366 | __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>()); |
| 1367 | } else if (rhs.IsConstant()) { |
| 1368 | int32_t constant = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); |
| 1369 | if (constant == 0) { |
| 1370 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); |
| 1371 | } else { |
| 1372 | __ cmpl(lhs.AsRegister<Register>(), Immediate(constant)); |
| 1373 | } |
| 1374 | } else { |
| 1375 | __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex())); |
| 1376 | } |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1377 | __ setb(X86SignedCondition(cond->GetCondition()), reg); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1378 | return; |
| 1379 | } |
| 1380 | case Primitive::kPrimLong: |
| 1381 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); |
| 1382 | break; |
| 1383 | case Primitive::kPrimFloat: |
| 1384 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1385 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1386 | break; |
| 1387 | case Primitive::kPrimDouble: |
| 1388 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); |
| 1389 | GenerateFPJumps(cond, &true_label, &false_label); |
| 1390 | break; |
| 1391 | } |
| 1392 | |
| 1393 | // Convert the jumps into the result. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1394 | NearLabel done_label; |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1395 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1396 | // False case: result = 0. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1397 | __ Bind(&false_label); |
| 1398 | __ xorl(reg, reg); |
| 1399 | __ jmp(&done_label); |
| 1400 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1401 | // True case: result = 1. |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1402 | __ Bind(&true_label); |
| 1403 | __ movl(reg, Immediate(1)); |
| 1404 | __ Bind(&done_label); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { |
| 1408 | VisitCondition(comp); |
| 1409 | } |
| 1410 | |
| 1411 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { |
| 1412 | VisitCondition(comp); |
| 1413 | } |
| 1414 | |
| 1415 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { |
| 1416 | VisitCondition(comp); |
| 1417 | } |
| 1418 | |
| 1419 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { |
| 1420 | VisitCondition(comp); |
| 1421 | } |
| 1422 | |
| 1423 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { |
| 1424 | VisitCondition(comp); |
| 1425 | } |
| 1426 | |
| 1427 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { |
| 1428 | VisitCondition(comp); |
| 1429 | } |
| 1430 | |
| 1431 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1432 | VisitCondition(comp); |
| 1433 | } |
| 1434 | |
| 1435 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { |
| 1436 | VisitCondition(comp); |
| 1437 | } |
| 1438 | |
| 1439 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1440 | VisitCondition(comp); |
| 1441 | } |
| 1442 | |
| 1443 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { |
| 1444 | VisitCondition(comp); |
| 1445 | } |
| 1446 | |
| 1447 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1448 | VisitCondition(comp); |
| 1449 | } |
| 1450 | |
| 1451 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { |
| 1452 | VisitCondition(comp); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1456 | LocationSummary* locations = |
| 1457 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1458 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1461 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) { |
Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1462 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1463 | UNUSED(constant); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1466 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { |
| 1467 | LocationSummary* locations = |
| 1468 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1469 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1470 | } |
| 1471 | |
| 1472 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant) { |
| 1473 | // Will be generated at use site. |
| 1474 | UNUSED(constant); |
| 1475 | } |
| 1476 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1477 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1478 | LocationSummary* locations = |
| 1479 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1480 | locations->SetOut(Location::ConstantLocation(constant)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) { |
| 1484 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1485 | UNUSED(constant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1486 | } |
| 1487 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1488 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1489 | LocationSummary* locations = |
| 1490 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1491 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1492 | } |
| 1493 | |
| 1494 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) { |
| 1495 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1496 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1500 | LocationSummary* locations = |
| 1501 | new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall); |
| 1502 | locations->SetOut(Location::ConstantLocation(constant)); |
| 1503 | } |
| 1504 | |
| 1505 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) { |
| 1506 | // Will be generated at use site. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1507 | UNUSED(constant); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1508 | } |
| 1509 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1510 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1511 | memory_barrier->SetLocations(nullptr); |
| 1512 | } |
| 1513 | |
| 1514 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { |
| 1515 | GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); |
| 1516 | } |
| 1517 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1518 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1519 | ret->SetLocations(nullptr); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1520 | } |
| 1521 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1522 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1523 | UNUSED(ret); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1524 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1527 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1528 | LocationSummary* locations = |
| 1529 | new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1530 | switch (ret->InputAt(0)->GetType()) { |
| 1531 | case Primitive::kPrimBoolean: |
| 1532 | case Primitive::kPrimByte: |
| 1533 | case Primitive::kPrimChar: |
| 1534 | case Primitive::kPrimShort: |
| 1535 | case Primitive::kPrimInt: |
| 1536 | case Primitive::kPrimNot: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1537 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1538 | break; |
| 1539 | |
| 1540 | case Primitive::kPrimLong: |
| 1541 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1542 | 0, Location::RegisterPairLocation(EAX, EDX)); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1543 | break; |
| 1544 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1545 | case Primitive::kPrimFloat: |
| 1546 | case Primitive::kPrimDouble: |
| 1547 | locations->SetInAt( |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1548 | 0, Location::FpuRegisterLocation(XMM0)); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1549 | break; |
| 1550 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1551 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1552 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1553 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1556 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1557 | if (kIsDebugBuild) { |
| 1558 | switch (ret->InputAt(0)->GetType()) { |
| 1559 | case Primitive::kPrimBoolean: |
| 1560 | case Primitive::kPrimByte: |
| 1561 | case Primitive::kPrimChar: |
| 1562 | case Primitive::kPrimShort: |
| 1563 | case Primitive::kPrimInt: |
| 1564 | case Primitive::kPrimNot: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1565 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1566 | break; |
| 1567 | |
| 1568 | case Primitive::kPrimLong: |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1569 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); |
| 1570 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1571 | break; |
| 1572 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1573 | case Primitive::kPrimFloat: |
| 1574 | case Primitive::kPrimDouble: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1575 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1576 | break; |
| 1577 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1578 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1579 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1580 | } |
| 1581 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1582 | codegen_->GenerateFrameExit(); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1585 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1586 | // The trampoline uses the same calling convention as dex calling conventions, |
| 1587 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 1588 | // the method_idx. |
| 1589 | HandleInvoke(invoke); |
| 1590 | } |
| 1591 | |
| 1592 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { |
| 1593 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); |
| 1594 | } |
| 1595 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1596 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1597 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1598 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1599 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1600 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1601 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1602 | if (intrinsic.TryDispatch(invoke)) { |
| 1603 | return; |
| 1604 | } |
| 1605 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1606 | HandleInvoke(invoke); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1607 | |
| 1608 | if (codegen_->IsBaseline()) { |
| 1609 | // Baseline does not have enough registers if the current method also |
| 1610 | // needs a register. We therefore do not require a register for it, and let |
| 1611 | // the code generation of the invoke handle it. |
| 1612 | LocationSummary* locations = invoke->GetLocations(); |
| 1613 | Location location = locations->InAt(invoke->GetCurrentMethodInputIndex()); |
| 1614 | if (location.IsUnallocated() && location.GetPolicy() == Location::kRequiresRegister) { |
| 1615 | locations->SetInAt(invoke->GetCurrentMethodInputIndex(), Location::NoLocation()); |
| 1616 | } |
| 1617 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1618 | } |
| 1619 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1620 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { |
| 1621 | if (invoke->GetLocations()->Intrinsified()) { |
| 1622 | IntrinsicCodeGeneratorX86 intrinsic(codegen); |
| 1623 | intrinsic.Dispatch(invoke); |
| 1624 | return true; |
| 1625 | } |
| 1626 | return false; |
| 1627 | } |
| 1628 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1629 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 1630 | // When we do not run baseline, explicit clinit checks triggered by static |
| 1631 | // invokes must have been pruned by art::PrepareForRegisterAllocation. |
| 1632 | DCHECK(codegen_->IsBaseline() || !invoke->IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1633 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1634 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1635 | return; |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1636 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1637 | |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1638 | LocationSummary* locations = invoke->GetLocations(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1639 | codegen_->GenerateStaticOrDirectCall( |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 1640 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); |
Mingyao Yang | 8693fe1 | 2015-04-17 16:51:08 -0700 | [diff] [blame] | 1641 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
| 1645 | HandleInvoke(invoke); |
| 1646 | } |
| 1647 | |
| 1648 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1649 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1650 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1653 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1654 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { |
| 1655 | return; |
| 1656 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1657 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 1658 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 1659 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1660 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1663 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1664 | HandleInvoke(invoke); |
| 1665 | // Add the hidden argument. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1666 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { |
| 1670 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1671 | Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1672 | uint32_t method_offset = mirror::Class::EmbeddedImTableEntryOffset( |
| 1673 | invoke->GetImtIndex() % mirror::Class::kImtSize, kX86PointerSize).Uint32Value(); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1674 | LocationSummary* locations = invoke->GetLocations(); |
| 1675 | Location receiver = locations->InAt(0); |
| 1676 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1677 | |
| 1678 | // Set the hidden argument. |
| 1679 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1680 | __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1681 | |
| 1682 | // temp = object->GetClass(); |
| 1683 | if (receiver.IsStackSlot()) { |
| 1684 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); |
| 1685 | __ movl(temp, Address(temp, class_offset)); |
| 1686 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1687 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1688 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1689 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1690 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1691 | // temp = temp->GetImtEntryAt(method_offset); |
| 1692 | __ movl(temp, Address(temp, method_offset)); |
| 1693 | // call temp->GetEntryPoint(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1694 | __ call(Address(temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
Nicolas Geoffray | 86a8d7a | 2014-11-19 08:47:18 +0000 | [diff] [blame] | 1695 | kX86WordSize).Int32Value())); |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1696 | |
| 1697 | DCHECK(!codegen_->IsLeafMethod()); |
| 1698 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1699 | } |
| 1700 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1701 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { |
| 1702 | LocationSummary* locations = |
| 1703 | new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall); |
| 1704 | switch (neg->GetResultType()) { |
| 1705 | case Primitive::kPrimInt: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1706 | case Primitive::kPrimLong: |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1707 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1708 | locations->SetOut(Location::SameAsFirstInput()); |
| 1709 | break; |
| 1710 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1711 | case Primitive::kPrimFloat: |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1712 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1713 | locations->SetOut(Location::SameAsFirstInput()); |
| 1714 | locations->AddTemp(Location::RequiresRegister()); |
| 1715 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1716 | break; |
| 1717 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1718 | case Primitive::kPrimDouble: |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1719 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1720 | locations->SetOut(Location::SameAsFirstInput()); |
| 1721 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1722 | break; |
| 1723 | |
| 1724 | default: |
| 1725 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { |
| 1730 | LocationSummary* locations = neg->GetLocations(); |
| 1731 | Location out = locations->Out(); |
| 1732 | Location in = locations->InAt(0); |
| 1733 | switch (neg->GetResultType()) { |
| 1734 | case Primitive::kPrimInt: |
| 1735 | DCHECK(in.IsRegister()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1736 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1737 | __ negl(out.AsRegister<Register>()); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1738 | break; |
| 1739 | |
| 1740 | case Primitive::kPrimLong: |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1741 | DCHECK(in.IsRegisterPair()); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1742 | DCHECK(in.Equals(out)); |
Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 1743 | __ negl(out.AsRegisterPairLow<Register>()); |
| 1744 | // Negation is similar to subtraction from zero. The least |
| 1745 | // significant byte triggers a borrow when it is different from |
| 1746 | // zero; to take it into account, add 1 to the most significant |
| 1747 | // byte if the carry flag (CF) is set to 1 after the first NEGL |
| 1748 | // operation. |
| 1749 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 1750 | __ negl(out.AsRegisterPairHigh<Register>()); |
| 1751 | break; |
| 1752 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1753 | case Primitive::kPrimFloat: { |
| 1754 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1755 | Register constant = locations->GetTemp(0).AsRegister<Register>(); |
| 1756 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1757 | // Implement float negation with an exclusive or with value |
| 1758 | // 0x80000000 (mask for bit 31, representing the sign of a |
| 1759 | // single-precision floating-point number). |
| 1760 | __ movl(constant, Immediate(INT32_C(0x80000000))); |
| 1761 | __ movd(mask, constant); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1762 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1763 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1764 | } |
Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 1765 | |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1766 | case Primitive::kPrimDouble: { |
| 1767 | DCHECK(in.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1768 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1769 | // Implement double negation with an exclusive or with value |
| 1770 | // 0x8000000000000000 (mask for bit 63, representing the sign of |
| 1771 | // a double-precision floating-point number). |
| 1772 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1773 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1774 | break; |
Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 1775 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1776 | |
| 1777 | default: |
| 1778 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); |
| 1779 | } |
| 1780 | } |
| 1781 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1782 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1783 | Primitive::Type result_type = conversion->GetResultType(); |
| 1784 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1785 | DCHECK_NE(result_type, input_type); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1786 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1787 | // The float-to-long and double-to-long type conversions rely on a |
| 1788 | // call to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1789 | LocationSummary::CallKind call_kind = |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1790 | ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble) |
| 1791 | && result_type == Primitive::kPrimLong) |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 1792 | ? LocationSummary::kCall |
| 1793 | : LocationSummary::kNoCall; |
| 1794 | LocationSummary* locations = |
| 1795 | new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind); |
| 1796 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1797 | // The Java language does not allow treating boolean as an integral type but |
| 1798 | // our bit representation makes it safe. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1799 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1800 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1801 | case Primitive::kPrimByte: |
| 1802 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1803 | case Primitive::kPrimBoolean: |
| 1804 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1805 | case Primitive::kPrimShort: |
| 1806 | case Primitive::kPrimInt: |
| 1807 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1808 | // Processing a Dex `int-to-byte' instruction. |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1809 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); |
| 1810 | // Make the output overlap to please the register allocator. This greatly simplifies |
| 1811 | // the validation of the linear scan implementation |
| 1812 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1813 | break; |
| 1814 | |
| 1815 | default: |
| 1816 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1817 | << " to " << result_type; |
| 1818 | } |
| 1819 | break; |
| 1820 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1821 | case Primitive::kPrimShort: |
| 1822 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1823 | case Primitive::kPrimBoolean: |
| 1824 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 1825 | case Primitive::kPrimByte: |
| 1826 | case Primitive::kPrimInt: |
| 1827 | case Primitive::kPrimChar: |
| 1828 | // Processing a Dex `int-to-short' instruction. |
| 1829 | locations->SetInAt(0, Location::Any()); |
| 1830 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1831 | break; |
| 1832 | |
| 1833 | default: |
| 1834 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1835 | << " to " << result_type; |
| 1836 | } |
| 1837 | break; |
| 1838 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1839 | case Primitive::kPrimInt: |
| 1840 | switch (input_type) { |
| 1841 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1842 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1843 | locations->SetInAt(0, Location::Any()); |
| 1844 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1845 | break; |
| 1846 | |
| 1847 | case Primitive::kPrimFloat: |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 1848 | // Processing a Dex `float-to-int' instruction. |
| 1849 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1850 | locations->SetOut(Location::RequiresRegister()); |
| 1851 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1852 | break; |
| 1853 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1854 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 1855 | // Processing a Dex `double-to-int' instruction. |
| 1856 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1857 | locations->SetOut(Location::RequiresRegister()); |
| 1858 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 1859 | break; |
| 1860 | |
| 1861 | default: |
| 1862 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1863 | << " to " << result_type; |
| 1864 | } |
| 1865 | break; |
| 1866 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1867 | case Primitive::kPrimLong: |
| 1868 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1869 | case Primitive::kPrimBoolean: |
| 1870 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1871 | case Primitive::kPrimByte: |
| 1872 | case Primitive::kPrimShort: |
| 1873 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 1874 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1875 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1876 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
| 1877 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 1878 | break; |
| 1879 | |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1880 | case Primitive::kPrimFloat: |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1881 | case Primitive::kPrimDouble: { |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1882 | // Processing a Dex `float-to-long' or 'double-to-long' instruction. |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1883 | InvokeRuntimeCallingConvention calling_convention; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1884 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); |
| 1885 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); |
| 1886 | |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1887 | // The runtime helper puts the result in EAX, EDX. |
| 1888 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 1889 | } |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1890 | break; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1891 | |
| 1892 | default: |
| 1893 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1894 | << " to " << result_type; |
| 1895 | } |
| 1896 | break; |
| 1897 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1898 | case Primitive::kPrimChar: |
| 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 | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1902 | case Primitive::kPrimByte: |
| 1903 | case Primitive::kPrimShort: |
| 1904 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1905 | // Processing a Dex `int-to-char' instruction. |
| 1906 | locations->SetInAt(0, Location::Any()); |
| 1907 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 1908 | break; |
| 1909 | |
| 1910 | default: |
| 1911 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1912 | << " to " << result_type; |
| 1913 | } |
| 1914 | break; |
| 1915 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1916 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1917 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1918 | case Primitive::kPrimBoolean: |
| 1919 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1920 | case Primitive::kPrimByte: |
| 1921 | case Primitive::kPrimShort: |
| 1922 | case Primitive::kPrimInt: |
| 1923 | case Primitive::kPrimChar: |
| 1924 | // Processing a Dex `int-to-float' instruction. |
| 1925 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1926 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1927 | break; |
| 1928 | |
| 1929 | case Primitive::kPrimLong: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1930 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 1931 | locations->SetInAt(0, Location::Any()); |
| 1932 | locations->SetOut(Location::Any()); |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 1933 | break; |
| 1934 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1935 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1936 | // Processing a Dex `double-to-float' instruction. |
| 1937 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1938 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 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::kPrimDouble: |
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-double' instruction. |
| 1956 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1957 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1958 | break; |
| 1959 | |
| 1960 | case Primitive::kPrimLong: |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1961 | // Processing a Dex `long-to-double' 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 | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 1964 | break; |
| 1965 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 1966 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 1967 | // Processing a Dex `float-to-double' 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 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1976 | break; |
| 1977 | |
| 1978 | default: |
| 1979 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 1980 | << " to " << result_type; |
| 1981 | } |
| 1982 | } |
| 1983 | |
| 1984 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { |
| 1985 | LocationSummary* locations = conversion->GetLocations(); |
| 1986 | Location out = locations->Out(); |
| 1987 | Location in = locations->InAt(0); |
| 1988 | Primitive::Type result_type = conversion->GetResultType(); |
| 1989 | Primitive::Type input_type = conversion->GetInputType(); |
Nicolas Geoffray | 01fcc9e | 2014-12-01 14:16:20 +0000 | [diff] [blame] | 1990 | DCHECK_NE(result_type, input_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1991 | switch (result_type) { |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1992 | case Primitive::kPrimByte: |
| 1993 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1994 | case Primitive::kPrimBoolean: |
| 1995 | // Boolean input is a result of code transformations. |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 1996 | case Primitive::kPrimShort: |
| 1997 | case Primitive::kPrimInt: |
| 1998 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 1999 | // Processing a Dex `int-to-byte' instruction. |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2000 | if (in.IsRegister()) { |
| 2001 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2002 | } else { |
| 2003 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2004 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
| 2005 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); |
| 2006 | } |
Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2007 | break; |
| 2008 | |
| 2009 | default: |
| 2010 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2011 | << " to " << result_type; |
| 2012 | } |
| 2013 | break; |
| 2014 | |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2015 | case Primitive::kPrimShort: |
| 2016 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2017 | case Primitive::kPrimBoolean: |
| 2018 | // Boolean input is a result of code transformations. |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2019 | case Primitive::kPrimByte: |
| 2020 | case Primitive::kPrimInt: |
| 2021 | case Primitive::kPrimChar: |
| 2022 | // Processing a Dex `int-to-short' instruction. |
| 2023 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2024 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2025 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2026 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2027 | } else { |
| 2028 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2029 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2030 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); |
Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2031 | } |
| 2032 | break; |
| 2033 | |
| 2034 | default: |
| 2035 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2036 | << " to " << result_type; |
| 2037 | } |
| 2038 | break; |
| 2039 | |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2040 | case Primitive::kPrimInt: |
| 2041 | switch (input_type) { |
| 2042 | case Primitive::kPrimLong: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2043 | // Processing a Dex `long-to-int' instruction. |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2044 | if (in.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2045 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2046 | } else if (in.IsDoubleStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2047 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2048 | } else { |
| 2049 | DCHECK(in.IsConstant()); |
| 2050 | DCHECK(in.GetConstant()->IsLongConstant()); |
| 2051 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2052 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2053 | } |
| 2054 | break; |
| 2055 | |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2056 | case Primitive::kPrimFloat: { |
| 2057 | // Processing a Dex `float-to-int' instruction. |
| 2058 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2059 | Register output = out.AsRegister<Register>(); |
| 2060 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2061 | NearLabel done, nan; |
Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2062 | |
| 2063 | __ movl(output, Immediate(kPrimIntMax)); |
| 2064 | // temp = int-to-float(output) |
| 2065 | __ cvtsi2ss(temp, output); |
| 2066 | // if input >= temp goto done |
| 2067 | __ comiss(input, temp); |
| 2068 | __ j(kAboveEqual, &done); |
| 2069 | // if input == NaN goto nan |
| 2070 | __ j(kUnordered, &nan); |
| 2071 | // output = float-to-int-truncate(input) |
| 2072 | __ cvttss2si(output, input); |
| 2073 | __ jmp(&done); |
| 2074 | __ Bind(&nan); |
| 2075 | // output = 0 |
| 2076 | __ xorl(output, output); |
| 2077 | __ Bind(&done); |
| 2078 | break; |
| 2079 | } |
| 2080 | |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2081 | case Primitive::kPrimDouble: { |
| 2082 | // Processing a Dex `double-to-int' instruction. |
| 2083 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); |
| 2084 | Register output = out.AsRegister<Register>(); |
| 2085 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2086 | NearLabel done, nan; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2087 | |
| 2088 | __ movl(output, Immediate(kPrimIntMax)); |
| 2089 | // temp = int-to-double(output) |
| 2090 | __ cvtsi2sd(temp, output); |
| 2091 | // if input >= temp goto done |
| 2092 | __ comisd(input, temp); |
| 2093 | __ j(kAboveEqual, &done); |
| 2094 | // if input == NaN goto nan |
| 2095 | __ j(kUnordered, &nan); |
| 2096 | // output = double-to-int-truncate(input) |
| 2097 | __ cvttsd2si(output, input); |
| 2098 | __ jmp(&done); |
| 2099 | __ Bind(&nan); |
| 2100 | // output = 0 |
| 2101 | __ xorl(output, output); |
| 2102 | __ Bind(&done); |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2103 | break; |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2104 | } |
Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2105 | |
| 2106 | default: |
| 2107 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2108 | << " to " << result_type; |
| 2109 | } |
| 2110 | break; |
| 2111 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2112 | case Primitive::kPrimLong: |
| 2113 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2114 | case Primitive::kPrimBoolean: |
| 2115 | // Boolean input is a result of code transformations. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2116 | case Primitive::kPrimByte: |
| 2117 | case Primitive::kPrimShort: |
| 2118 | case Primitive::kPrimInt: |
Roland Levillain | 666c732 | 2014-11-10 13:39:43 +0000 | [diff] [blame] | 2119 | case Primitive::kPrimChar: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2120 | // Processing a Dex `int-to-long' instruction. |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2121 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); |
| 2122 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2123 | DCHECK_EQ(in.AsRegister<Register>(), EAX); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2124 | __ cdq(); |
| 2125 | break; |
| 2126 | |
| 2127 | case Primitive::kPrimFloat: |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2128 | // Processing a Dex `float-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2129 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l), |
| 2130 | conversion, |
| 2131 | conversion->GetDexPc(), |
| 2132 | nullptr); |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2133 | break; |
| 2134 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2135 | case Primitive::kPrimDouble: |
Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2136 | // Processing a Dex `double-to-long' instruction. |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2137 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l), |
| 2138 | conversion, |
| 2139 | conversion->GetDexPc(), |
| 2140 | nullptr); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2141 | break; |
| 2142 | |
| 2143 | default: |
| 2144 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2145 | << " to " << result_type; |
| 2146 | } |
| 2147 | break; |
| 2148 | |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2149 | case Primitive::kPrimChar: |
| 2150 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2151 | case Primitive::kPrimBoolean: |
| 2152 | // Boolean input is a result of code transformations. |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2153 | case Primitive::kPrimByte: |
| 2154 | case Primitive::kPrimShort: |
| 2155 | case Primitive::kPrimInt: |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2156 | // Processing a Dex `Process a Dex `int-to-char'' instruction. |
| 2157 | if (in.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2158 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2159 | } else if (in.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2160 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2161 | } else { |
| 2162 | DCHECK(in.GetConstant()->IsIntConstant()); |
| 2163 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2164 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); |
Roland Levillain | 981e454 | 2014-11-14 11:47:14 +0000 | [diff] [blame] | 2165 | } |
| 2166 | break; |
| 2167 | |
| 2168 | default: |
| 2169 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2170 | << " to " << result_type; |
| 2171 | } |
| 2172 | break; |
| 2173 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2174 | case Primitive::kPrimFloat: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2175 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2176 | case Primitive::kPrimBoolean: |
| 2177 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2178 | case Primitive::kPrimByte: |
| 2179 | case Primitive::kPrimShort: |
| 2180 | case Primitive::kPrimInt: |
| 2181 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2182 | // Processing a Dex `int-to-float' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2183 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2184 | break; |
| 2185 | |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2186 | case Primitive::kPrimLong: { |
| 2187 | // Processing a Dex `long-to-float' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2188 | size_t adjustment = 0; |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2189 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2190 | // Create stack space for the call to |
| 2191 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. |
| 2192 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2193 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { |
| 2194 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2195 | __ subl(ESP, Immediate(adjustment)); |
| 2196 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2197 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2198 | // Load the value to the FP stack, using temporaries if needed. |
| 2199 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2200 | |
| 2201 | if (out.IsStackSlot()) { |
| 2202 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2203 | } else { |
| 2204 | __ fstps(Address(ESP, 0)); |
| 2205 | Location stack_temp = Location::StackSlot(0); |
| 2206 | codegen_->Move32(out, stack_temp); |
| 2207 | } |
| 2208 | |
| 2209 | // Remove the temporary stack space we allocated. |
| 2210 | if (adjustment != 0) { |
| 2211 | __ addl(ESP, Immediate(adjustment)); |
| 2212 | } |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2213 | break; |
| 2214 | } |
| 2215 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2216 | case Primitive::kPrimDouble: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2217 | // Processing a Dex `double-to-float' instruction. |
| 2218 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2219 | break; |
| 2220 | |
| 2221 | default: |
| 2222 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2223 | << " to " << result_type; |
| 2224 | }; |
| 2225 | break; |
| 2226 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2227 | case Primitive::kPrimDouble: |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2228 | switch (input_type) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 2229 | case Primitive::kPrimBoolean: |
| 2230 | // Boolean input is a result of code transformations. |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2231 | case Primitive::kPrimByte: |
| 2232 | case Primitive::kPrimShort: |
| 2233 | case Primitive::kPrimInt: |
| 2234 | case Primitive::kPrimChar: |
Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2235 | // Processing a Dex `int-to-double' instruction. |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2236 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2237 | break; |
| 2238 | |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2239 | case Primitive::kPrimLong: { |
| 2240 | // Processing a Dex `long-to-double' instruction. |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2241 | size_t adjustment = 0; |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2242 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2243 | // Create stack space for the call to |
| 2244 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. |
| 2245 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2246 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { |
| 2247 | adjustment = Primitive::ComponentSize(Primitive::kPrimLong); |
| 2248 | __ subl(ESP, Immediate(adjustment)); |
| 2249 | } |
| 2250 | |
| 2251 | // Load the value to the FP stack, using temporaries if needed. |
| 2252 | PushOntoFPStack(in, 0, adjustment, false, true); |
| 2253 | |
| 2254 | if (out.IsDoubleStackSlot()) { |
| 2255 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); |
| 2256 | } else { |
| 2257 | __ fstpl(Address(ESP, 0)); |
| 2258 | Location stack_temp = Location::DoubleStackSlot(0); |
| 2259 | codegen_->Move64(out, stack_temp); |
| 2260 | } |
| 2261 | |
| 2262 | // Remove the temporary stack space we allocated. |
| 2263 | if (adjustment != 0) { |
| 2264 | __ addl(ESP, Immediate(adjustment)); |
| 2265 | } |
Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2266 | break; |
| 2267 | } |
| 2268 | |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2269 | case Primitive::kPrimFloat: |
Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2270 | // Processing a Dex `float-to-double' instruction. |
| 2271 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); |
Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2272 | break; |
| 2273 | |
| 2274 | default: |
| 2275 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2276 | << " to " << result_type; |
| 2277 | }; |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2278 | break; |
| 2279 | |
| 2280 | default: |
| 2281 | LOG(FATAL) << "Unexpected type conversion from " << input_type |
| 2282 | << " to " << result_type; |
| 2283 | } |
| 2284 | } |
| 2285 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2286 | void LocationsBuilderX86::VisitAdd(HAdd* add) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2287 | LocationSummary* locations = |
| 2288 | new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2289 | switch (add->GetResultType()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2290 | case Primitive::kPrimInt: { |
| 2291 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2292 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); |
| 2293 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2294 | break; |
| 2295 | } |
| 2296 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2297 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2298 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2299 | locations->SetInAt(1, Location::Any()); |
| 2300 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2301 | break; |
| 2302 | } |
| 2303 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2304 | case Primitive::kPrimFloat: |
| 2305 | case Primitive::kPrimDouble: { |
| 2306 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2307 | locations->SetInAt(1, Location::Any()); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2308 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2309 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2310 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2311 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2312 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2313 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
| 2314 | break; |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2315 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { |
| 2319 | LocationSummary* locations = add->GetLocations(); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2320 | Location first = locations->InAt(0); |
| 2321 | Location second = locations->InAt(1); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2322 | Location out = locations->Out(); |
| 2323 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2324 | switch (add->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2325 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2326 | if (second.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2327 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2328 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); |
Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 2329 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { |
| 2330 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2331 | } else { |
| 2332 | __ leal(out.AsRegister<Register>(), Address( |
| 2333 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); |
| 2334 | } |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2335 | } else if (second.IsConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2336 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); |
| 2337 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { |
| 2338 | __ addl(out.AsRegister<Register>(), Immediate(value)); |
| 2339 | } else { |
| 2340 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); |
| 2341 | } |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2342 | } else { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2343 | DCHECK(first.Equals(locations->Out())); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2344 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2345 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2346 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2350 | if (second.IsRegisterPair()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2351 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2352 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2353 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2354 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 2355 | __ adcl(first.AsRegisterPairHigh<Register>(), |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2356 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2357 | } else { |
| 2358 | DCHECK(second.IsConstant()) << second; |
| 2359 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2360 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2361 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2362 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2363 | break; |
| 2364 | } |
| 2365 | |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2366 | case Primitive::kPrimFloat: { |
| 2367 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2368 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2369 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2370 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2371 | DCHECK(!const_area->NeedsMaterialization()); |
| 2372 | __ addss(first.AsFpuRegister<XmmRegister>(), |
| 2373 | codegen_->LiteralFloatAddress( |
| 2374 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2375 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2376 | } else { |
| 2377 | DCHECK(second.IsStackSlot()); |
| 2378 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2379 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2380 | break; |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | case Primitive::kPrimDouble: { |
| 2384 | if (second.IsFpuRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2385 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2386 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2387 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2388 | DCHECK(!const_area->NeedsMaterialization()); |
| 2389 | __ addsd(first.AsFpuRegister<XmmRegister>(), |
| 2390 | codegen_->LiteralDoubleAddress( |
| 2391 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2392 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2393 | } else { |
| 2394 | DCHECK(second.IsDoubleStackSlot()); |
| 2395 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2396 | } |
| 2397 | break; |
| 2398 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2399 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2400 | default: |
Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2401 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2402 | } |
| 2403 | } |
| 2404 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2405 | void LocationsBuilderX86::VisitSub(HSub* sub) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2406 | LocationSummary* locations = |
| 2407 | new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2408 | switch (sub->GetResultType()) { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2409 | case Primitive::kPrimInt: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2410 | case Primitive::kPrimLong: { |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2411 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2412 | locations->SetInAt(1, Location::Any()); |
| 2413 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2414 | break; |
| 2415 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2416 | case Primitive::kPrimFloat: |
| 2417 | case Primitive::kPrimDouble: { |
| 2418 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2419 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2420 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2421 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2422 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2423 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2424 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2425 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2426 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { |
| 2430 | LocationSummary* locations = sub->GetLocations(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2431 | Location first = locations->InAt(0); |
| 2432 | Location second = locations->InAt(1); |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2433 | DCHECK(first.Equals(locations->Out())); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2434 | switch (sub->GetResultType()) { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2435 | case Primitive::kPrimInt: { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2436 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2437 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2438 | } else if (second.IsConstant()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2439 | __ subl(first.AsRegister<Register>(), |
| 2440 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2441 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2442 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2443 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2444 | break; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | case Primitive::kPrimLong: { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 2448 | if (second.IsRegisterPair()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2449 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 2450 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2451 | } else if (second.IsDoubleStackSlot()) { |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2452 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2453 | __ sbbl(first.AsRegisterPairHigh<Register>(), |
| 2454 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2455 | } else { |
| 2456 | DCHECK(second.IsConstant()) << second; |
| 2457 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2458 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); |
| 2459 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2460 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2461 | break; |
| 2462 | } |
| 2463 | |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2464 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2465 | if (second.IsFpuRegister()) { |
| 2466 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2467 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2468 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2469 | DCHECK(!const_area->NeedsMaterialization()); |
| 2470 | __ subss(first.AsFpuRegister<XmmRegister>(), |
| 2471 | codegen_->LiteralFloatAddress( |
| 2472 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2473 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2474 | } else { |
| 2475 | DCHECK(second.IsStackSlot()); |
| 2476 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2477 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2478 | break; |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2482 | if (second.IsFpuRegister()) { |
| 2483 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2484 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2485 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2486 | DCHECK(!const_area->NeedsMaterialization()); |
| 2487 | __ subsd(first.AsFpuRegister<XmmRegister>(), |
| 2488 | codegen_->LiteralDoubleAddress( |
| 2489 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2490 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2491 | } else { |
| 2492 | DCHECK(second.IsDoubleStackSlot()); |
| 2493 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2494 | } |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2495 | break; |
| 2496 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2497 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2498 | default: |
Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 2499 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 2500 | } |
| 2501 | } |
| 2502 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2503 | void LocationsBuilderX86::VisitMul(HMul* mul) { |
| 2504 | LocationSummary* locations = |
| 2505 | new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall); |
| 2506 | switch (mul->GetResultType()) { |
| 2507 | case Primitive::kPrimInt: |
| 2508 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2509 | locations->SetInAt(1, Location::Any()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2510 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2511 | // Can use 3 operand multiply. |
| 2512 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 2513 | } else { |
| 2514 | locations->SetOut(Location::SameAsFirstInput()); |
| 2515 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2516 | break; |
| 2517 | case Primitive::kPrimLong: { |
| 2518 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2519 | locations->SetInAt(1, Location::Any()); |
| 2520 | locations->SetOut(Location::SameAsFirstInput()); |
| 2521 | // Needed for imul on 32bits with 64bits output. |
| 2522 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 2523 | locations->AddTemp(Location::RegisterLocation(EDX)); |
| 2524 | break; |
| 2525 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2526 | case Primitive::kPrimFloat: |
| 2527 | case Primitive::kPrimDouble: { |
| 2528 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2529 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2530 | locations->SetOut(Location::SameAsFirstInput()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2531 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2532 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2533 | |
| 2534 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2535 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { |
| 2540 | LocationSummary* locations = mul->GetLocations(); |
| 2541 | Location first = locations->InAt(0); |
| 2542 | Location second = locations->InAt(1); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2543 | Location out = locations->Out(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2544 | |
| 2545 | switch (mul->GetResultType()) { |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2546 | case Primitive::kPrimInt: |
| 2547 | // The constant may have ended up in a register, so test explicitly to avoid |
| 2548 | // problems where the output may not be the same as the first operand. |
| 2549 | if (mul->InputAt(1)->IsIntConstant()) { |
| 2550 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); |
| 2551 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); |
| 2552 | } else if (second.IsRegister()) { |
| 2553 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2554 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2555 | } else { |
| 2556 | DCHECK(second.IsStackSlot()); |
Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 2557 | DCHECK(first.Equals(out)); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2558 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2559 | } |
| 2560 | break; |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2561 | |
| 2562 | case Primitive::kPrimLong: { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2563 | Register in1_hi = first.AsRegisterPairHigh<Register>(); |
| 2564 | Register in1_lo = first.AsRegisterPairLow<Register>(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2565 | Register eax = locations->GetTemp(0).AsRegister<Register>(); |
| 2566 | Register edx = locations->GetTemp(1).AsRegister<Register>(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2567 | |
| 2568 | DCHECK_EQ(EAX, eax); |
| 2569 | DCHECK_EQ(EDX, edx); |
| 2570 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2571 | // input: in1 - 64 bits, in2 - 64 bits. |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2572 | // output: in1 |
| 2573 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo |
| 2574 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] |
| 2575 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2576 | if (second.IsConstant()) { |
| 2577 | DCHECK(second.GetConstant()->IsLongConstant()); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2578 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2579 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
| 2580 | int32_t low_value = Low32Bits(value); |
| 2581 | int32_t high_value = High32Bits(value); |
| 2582 | Immediate low(low_value); |
| 2583 | Immediate high(high_value); |
| 2584 | |
| 2585 | __ movl(eax, high); |
| 2586 | // eax <- in1.lo * in2.hi |
| 2587 | __ imull(eax, in1_lo); |
| 2588 | // in1.hi <- in1.hi * in2.lo |
| 2589 | __ imull(in1_hi, low); |
| 2590 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2591 | __ addl(in1_hi, eax); |
| 2592 | // move in2_lo to eax to prepare for double precision |
| 2593 | __ movl(eax, low); |
| 2594 | // edx:eax <- in1.lo * in2.lo |
| 2595 | __ mull(in1_lo); |
| 2596 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2597 | __ addl(in1_hi, edx); |
| 2598 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2599 | __ movl(in1_lo, eax); |
| 2600 | } else if (second.IsRegisterPair()) { |
| 2601 | Register in2_hi = second.AsRegisterPairHigh<Register>(); |
| 2602 | Register in2_lo = second.AsRegisterPairLow<Register>(); |
| 2603 | |
| 2604 | __ movl(eax, in2_hi); |
| 2605 | // eax <- in1.lo * in2.hi |
| 2606 | __ imull(eax, in1_lo); |
| 2607 | // in1.hi <- in1.hi * in2.lo |
| 2608 | __ imull(in1_hi, in2_lo); |
| 2609 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2610 | __ addl(in1_hi, eax); |
| 2611 | // move in1_lo to eax to prepare for double precision |
| 2612 | __ movl(eax, in1_lo); |
| 2613 | // edx:eax <- in1.lo * in2.lo |
| 2614 | __ mull(in2_lo); |
| 2615 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2616 | __ addl(in1_hi, edx); |
| 2617 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2618 | __ movl(in1_lo, eax); |
| 2619 | } else { |
| 2620 | DCHECK(second.IsDoubleStackSlot()) << second; |
| 2621 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); |
| 2622 | Address in2_lo(ESP, second.GetStackIndex()); |
| 2623 | |
| 2624 | __ movl(eax, in2_hi); |
| 2625 | // eax <- in1.lo * in2.hi |
| 2626 | __ imull(eax, in1_lo); |
| 2627 | // in1.hi <- in1.hi * in2.lo |
| 2628 | __ imull(in1_hi, in2_lo); |
| 2629 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo |
| 2630 | __ addl(in1_hi, eax); |
| 2631 | // move in1_lo to eax to prepare for double precision |
| 2632 | __ movl(eax, in1_lo); |
| 2633 | // edx:eax <- in1.lo * in2.lo |
| 2634 | __ mull(in2_lo); |
| 2635 | // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] |
| 2636 | __ addl(in1_hi, edx); |
| 2637 | // in1.lo <- (in1.lo * in2.lo)[31:0]; |
| 2638 | __ movl(in1_lo, eax); |
| 2639 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2640 | |
| 2641 | break; |
| 2642 | } |
| 2643 | |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2644 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2645 | DCHECK(first.Equals(locations->Out())); |
| 2646 | if (second.IsFpuRegister()) { |
| 2647 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2648 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2649 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2650 | DCHECK(!const_area->NeedsMaterialization()); |
| 2651 | __ mulss(first.AsFpuRegister<XmmRegister>(), |
| 2652 | codegen_->LiteralFloatAddress( |
| 2653 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 2654 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2655 | } else { |
| 2656 | DCHECK(second.IsStackSlot()); |
| 2657 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2658 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2659 | break; |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 2663 | DCHECK(first.Equals(locations->Out())); |
| 2664 | if (second.IsFpuRegister()) { |
| 2665 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 2666 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 2667 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); |
| 2668 | DCHECK(!const_area->NeedsMaterialization()); |
| 2669 | __ mulsd(first.AsFpuRegister<XmmRegister>(), |
| 2670 | codegen_->LiteralDoubleAddress( |
| 2671 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 2672 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 2673 | } else { |
| 2674 | DCHECK(second.IsDoubleStackSlot()); |
| 2675 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 2676 | } |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2677 | break; |
| 2678 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2679 | |
| 2680 | default: |
Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 2681 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 2682 | } |
| 2683 | } |
| 2684 | |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2685 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, |
| 2686 | uint32_t temp_offset, |
| 2687 | uint32_t stack_adjustment, |
| 2688 | bool is_fp, |
| 2689 | bool is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2690 | if (source.IsStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2691 | DCHECK(!is_wide); |
| 2692 | if (is_fp) { |
| 2693 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2694 | } else { |
| 2695 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2696 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2697 | } else if (source.IsDoubleStackSlot()) { |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2698 | DCHECK(is_wide); |
| 2699 | if (is_fp) { |
| 2700 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2701 | } else { |
| 2702 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); |
| 2703 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2704 | } else { |
| 2705 | // 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] | 2706 | if (!is_wide) { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2707 | Location stack_temp = Location::StackSlot(temp_offset); |
| 2708 | codegen_->Move32(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2709 | if (is_fp) { |
| 2710 | __ flds(Address(ESP, temp_offset)); |
| 2711 | } else { |
| 2712 | __ filds(Address(ESP, temp_offset)); |
| 2713 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2714 | } else { |
| 2715 | Location stack_temp = Location::DoubleStackSlot(temp_offset); |
| 2716 | codegen_->Move64(stack_temp, source); |
Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2717 | if (is_fp) { |
| 2718 | __ fldl(Address(ESP, temp_offset)); |
| 2719 | } else { |
| 2720 | __ fildl(Address(ESP, temp_offset)); |
| 2721 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2722 | } |
| 2723 | } |
| 2724 | } |
| 2725 | |
| 2726 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { |
| 2727 | Primitive::Type type = rem->GetResultType(); |
| 2728 | bool is_float = type == Primitive::kPrimFloat; |
| 2729 | size_t elem_size = Primitive::ComponentSize(type); |
| 2730 | LocationSummary* locations = rem->GetLocations(); |
| 2731 | Location first = locations->InAt(0); |
| 2732 | Location second = locations->InAt(1); |
| 2733 | Location out = locations->Out(); |
| 2734 | |
| 2735 | // Create stack space for 2 elements. |
| 2736 | // TODO: enhance register allocator to ask for stack temporaries. |
| 2737 | __ subl(ESP, Immediate(2 * elem_size)); |
| 2738 | |
| 2739 | // 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] | 2740 | const bool is_wide = !is_float; |
| 2741 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp */ true, is_wide); |
| 2742 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp */ true, is_wide); |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2743 | |
| 2744 | // Loop doing FPREM until we stabilize. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2745 | NearLabel retry; |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 2746 | __ Bind(&retry); |
| 2747 | __ fprem(); |
| 2748 | |
| 2749 | // Move FP status to AX. |
| 2750 | __ fstsw(); |
| 2751 | |
| 2752 | // And see if the argument reduction is complete. This is signaled by the |
| 2753 | // C2 FPU flag bit set to 0. |
| 2754 | __ andl(EAX, Immediate(kC2ConditionMask)); |
| 2755 | __ j(kNotEqual, &retry); |
| 2756 | |
| 2757 | // We have settled on the final value. Retrieve it into an XMM register. |
| 2758 | // Store FP top of stack to real stack. |
| 2759 | if (is_float) { |
| 2760 | __ fsts(Address(ESP, 0)); |
| 2761 | } else { |
| 2762 | __ fstl(Address(ESP, 0)); |
| 2763 | } |
| 2764 | |
| 2765 | // Pop the 2 items from the FP stack. |
| 2766 | __ fucompp(); |
| 2767 | |
| 2768 | // Load the value from the stack into an XMM register. |
| 2769 | DCHECK(out.IsFpuRegister()) << out; |
| 2770 | if (is_float) { |
| 2771 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2772 | } else { |
| 2773 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); |
| 2774 | } |
| 2775 | |
| 2776 | // And remove the temporary stack space we allocated. |
| 2777 | __ addl(ESP, Immediate(2 * elem_size)); |
| 2778 | } |
| 2779 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2780 | |
| 2781 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { |
| 2782 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2783 | |
| 2784 | LocationSummary* locations = instruction->GetLocations(); |
| 2785 | DCHECK(locations->InAt(1).IsConstant()); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2786 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2787 | |
| 2788 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2789 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2790 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2791 | |
| 2792 | DCHECK(imm == 1 || imm == -1); |
| 2793 | |
| 2794 | if (instruction->IsRem()) { |
| 2795 | __ xorl(out_register, out_register); |
| 2796 | } else { |
| 2797 | __ movl(out_register, input_register); |
| 2798 | if (imm == -1) { |
| 2799 | __ negl(out_register); |
| 2800 | } |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2805 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2806 | LocationSummary* locations = instruction->GetLocations(); |
| 2807 | |
| 2808 | Register out_register = locations->Out().AsRegister<Register>(); |
| 2809 | Register input_register = locations->InAt(0).AsRegister<Register>(); |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2810 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2811 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2812 | DCHECK(IsPowerOfTwo(std::abs(imm))); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2813 | Register num = locations->GetTemp(0).AsRegister<Register>(); |
| 2814 | |
| 2815 | __ leal(num, Address(input_register, std::abs(imm) - 1)); |
| 2816 | __ testl(input_register, input_register); |
| 2817 | __ cmovl(kGreaterEqual, num, input_register); |
| 2818 | int shift = CTZ(imm); |
| 2819 | __ sarl(num, Immediate(shift)); |
| 2820 | |
| 2821 | if (imm < 0) { |
| 2822 | __ negl(num); |
| 2823 | } |
| 2824 | |
| 2825 | __ movl(out_register, num); |
| 2826 | } |
| 2827 | |
| 2828 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { |
| 2829 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2830 | |
| 2831 | LocationSummary* locations = instruction->GetLocations(); |
| 2832 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 2833 | |
| 2834 | Register eax = locations->InAt(0).AsRegister<Register>(); |
| 2835 | Register out = locations->Out().AsRegister<Register>(); |
| 2836 | Register num; |
| 2837 | Register edx; |
| 2838 | |
| 2839 | if (instruction->IsDiv()) { |
| 2840 | edx = locations->GetTemp(0).AsRegister<Register>(); |
| 2841 | num = locations->GetTemp(1).AsRegister<Register>(); |
| 2842 | } else { |
| 2843 | edx = locations->Out().AsRegister<Register>(); |
| 2844 | num = locations->GetTemp(0).AsRegister<Register>(); |
| 2845 | } |
| 2846 | |
| 2847 | DCHECK_EQ(EAX, eax); |
| 2848 | DCHECK_EQ(EDX, edx); |
| 2849 | if (instruction->IsDiv()) { |
| 2850 | DCHECK_EQ(EAX, out); |
| 2851 | } else { |
| 2852 | DCHECK_EQ(EDX, out); |
| 2853 | } |
| 2854 | |
| 2855 | int64_t magic; |
| 2856 | int shift; |
| 2857 | CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift); |
| 2858 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2859 | NearLabel ndiv; |
| 2860 | NearLabel end; |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2861 | // If numerator is 0, the result is 0, no computation needed. |
| 2862 | __ testl(eax, eax); |
| 2863 | __ j(kNotEqual, &ndiv); |
| 2864 | |
| 2865 | __ xorl(out, out); |
| 2866 | __ jmp(&end); |
| 2867 | |
| 2868 | __ Bind(&ndiv); |
| 2869 | |
| 2870 | // Save the numerator. |
| 2871 | __ movl(num, eax); |
| 2872 | |
| 2873 | // EAX = magic |
| 2874 | __ movl(eax, Immediate(magic)); |
| 2875 | |
| 2876 | // EDX:EAX = magic * numerator |
| 2877 | __ imull(num); |
| 2878 | |
| 2879 | if (imm > 0 && magic < 0) { |
| 2880 | // EDX += num |
| 2881 | __ addl(edx, num); |
| 2882 | } else if (imm < 0 && magic > 0) { |
| 2883 | __ subl(edx, num); |
| 2884 | } |
| 2885 | |
| 2886 | // Shift if needed. |
| 2887 | if (shift != 0) { |
| 2888 | __ sarl(edx, Immediate(shift)); |
| 2889 | } |
| 2890 | |
| 2891 | // EDX += 1 if EDX < 0 |
| 2892 | __ movl(eax, edx); |
| 2893 | __ shrl(edx, Immediate(31)); |
| 2894 | __ addl(edx, eax); |
| 2895 | |
| 2896 | if (instruction->IsRem()) { |
| 2897 | __ movl(eax, num); |
| 2898 | __ imull(edx, Immediate(imm)); |
| 2899 | __ subl(eax, edx); |
| 2900 | __ movl(edx, eax); |
| 2901 | } else { |
| 2902 | __ movl(eax, edx); |
| 2903 | } |
| 2904 | __ Bind(&end); |
| 2905 | } |
| 2906 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2907 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { |
| 2908 | DCHECK(instruction->IsDiv() || instruction->IsRem()); |
| 2909 | |
| 2910 | LocationSummary* locations = instruction->GetLocations(); |
| 2911 | Location out = locations->Out(); |
| 2912 | Location first = locations->InAt(0); |
| 2913 | Location second = locations->InAt(1); |
| 2914 | bool is_div = instruction->IsDiv(); |
| 2915 | |
| 2916 | switch (instruction->GetResultType()) { |
| 2917 | case Primitive::kPrimInt: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2918 | DCHECK_EQ(EAX, first.AsRegister<Register>()); |
| 2919 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2920 | |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2921 | if (instruction->InputAt(1)->IsIntConstant()) { |
| 2922 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2923 | |
| 2924 | if (imm == 0) { |
| 2925 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. |
| 2926 | } else if (imm == 1 || imm == -1) { |
| 2927 | DivRemOneOrMinusOne(instruction); |
| 2928 | } else if (is_div && IsPowerOfTwo(std::abs(imm))) { |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 2929 | DivByPowerOfTwo(instruction->AsDiv()); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2930 | } else { |
| 2931 | DCHECK(imm <= -2 || imm >= 2); |
| 2932 | GenerateDivRemWithAnyConstant(instruction); |
| 2933 | } |
| 2934 | } else { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 2935 | SlowPathCode* slow_path = |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 2936 | new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(), |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2937 | is_div); |
| 2938 | codegen_->AddSlowPath(slow_path); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2939 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2940 | Register second_reg = second.AsRegister<Register>(); |
| 2941 | // 0x80000000/-1 triggers an arithmetic exception! |
| 2942 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so |
| 2943 | // it's safe to just use negl instead of more complex comparisons. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2944 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2945 | __ cmpl(second_reg, Immediate(-1)); |
| 2946 | __ j(kEqual, slow_path->GetEntryLabel()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2947 | |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2948 | // edx:eax <- sign-extended of eax |
| 2949 | __ cdq(); |
| 2950 | // eax = quotient, edx = remainder |
| 2951 | __ idivl(second_reg); |
| 2952 | __ Bind(slow_path->GetExitLabel()); |
| 2953 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2954 | break; |
| 2955 | } |
| 2956 | |
| 2957 | case Primitive::kPrimLong: { |
| 2958 | InvokeRuntimeCallingConvention calling_convention; |
| 2959 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); |
| 2960 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); |
| 2961 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); |
| 2962 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); |
| 2963 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); |
| 2964 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); |
| 2965 | |
| 2966 | if (is_div) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2967 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), |
| 2968 | instruction, |
| 2969 | instruction->GetDexPc(), |
| 2970 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2971 | } else { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 2972 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), |
| 2973 | instruction, |
| 2974 | instruction->GetDexPc(), |
| 2975 | nullptr); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2976 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 2977 | break; |
| 2978 | } |
| 2979 | |
| 2980 | default: |
| 2981 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); |
| 2982 | } |
| 2983 | } |
| 2984 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2985 | void LocationsBuilderX86::VisitDiv(HDiv* div) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 2986 | LocationSummary::CallKind call_kind = (div->GetResultType() == Primitive::kPrimLong) |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 2987 | ? LocationSummary::kCall |
| 2988 | : LocationSummary::kNoCall; |
| 2989 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind); |
| 2990 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 2991 | switch (div->GetResultType()) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2992 | case Primitive::kPrimInt: { |
| 2993 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2994 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 2995 | locations->SetOut(Location::SameAsFirstInput()); |
| 2996 | // Intel uses edx:eax as the dividend. |
| 2997 | locations->AddTemp(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 2998 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 2999 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as |
| 3000 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3001 | if (div->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3002 | locations->AddTemp(Location::RequiresRegister()); |
| 3003 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3004 | break; |
| 3005 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3006 | case Primitive::kPrimLong: { |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3007 | InvokeRuntimeCallingConvention calling_convention; |
| 3008 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3009 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3010 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3011 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3012 | // Runtime helper puts the result in EAX, EDX. |
| 3013 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3014 | break; |
| 3015 | } |
| 3016 | case Primitive::kPrimFloat: |
| 3017 | case Primitive::kPrimDouble: { |
| 3018 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3019 | locations->SetInAt(1, Location::Any()); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3020 | locations->SetOut(Location::SameAsFirstInput()); |
| 3021 | break; |
| 3022 | } |
| 3023 | |
| 3024 | default: |
| 3025 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3026 | } |
| 3027 | } |
| 3028 | |
| 3029 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { |
| 3030 | LocationSummary* locations = div->GetLocations(); |
| 3031 | Location first = locations->InAt(0); |
| 3032 | Location second = locations->InAt(1); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3033 | |
| 3034 | switch (div->GetResultType()) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3035 | case Primitive::kPrimInt: |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3036 | case Primitive::kPrimLong: { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3037 | GenerateDivRemIntegral(div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3038 | break; |
| 3039 | } |
| 3040 | |
| 3041 | case Primitive::kPrimFloat: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3042 | if (second.IsFpuRegister()) { |
| 3043 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3044 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3045 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3046 | DCHECK(!const_area->NeedsMaterialization()); |
| 3047 | __ divss(first.AsFpuRegister<XmmRegister>(), |
| 3048 | codegen_->LiteralFloatAddress( |
| 3049 | const_area->GetConstant()->AsFloatConstant()->GetValue(), |
| 3050 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3051 | } else { |
| 3052 | DCHECK(second.IsStackSlot()); |
| 3053 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3054 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3055 | break; |
| 3056 | } |
| 3057 | |
| 3058 | case Primitive::kPrimDouble: { |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3059 | if (second.IsFpuRegister()) { |
| 3060 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); |
| 3061 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { |
| 3062 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); |
| 3063 | DCHECK(!const_area->NeedsMaterialization()); |
| 3064 | __ divsd(first.AsFpuRegister<XmmRegister>(), |
| 3065 | codegen_->LiteralDoubleAddress( |
| 3066 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), |
| 3067 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); |
| 3068 | } else { |
| 3069 | DCHECK(second.IsDoubleStackSlot()); |
| 3070 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); |
| 3071 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3072 | break; |
| 3073 | } |
| 3074 | |
| 3075 | default: |
| 3076 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); |
| 3077 | } |
| 3078 | } |
| 3079 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3080 | void LocationsBuilderX86::VisitRem(HRem* rem) { |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3081 | Primitive::Type type = rem->GetResultType(); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3082 | |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3083 | LocationSummary::CallKind call_kind = (rem->GetResultType() == Primitive::kPrimLong) |
| 3084 | ? LocationSummary::kCall |
| 3085 | : LocationSummary::kNoCall; |
| 3086 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3087 | |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3088 | switch (type) { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3089 | case Primitive::kPrimInt: { |
| 3090 | locations->SetInAt(0, Location::RegisterLocation(EAX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3091 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3092 | locations->SetOut(Location::RegisterLocation(EDX)); |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3093 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way |
| 3094 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as |
| 3095 | // output and request another temp. |
Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3096 | if (rem->InputAt(1)->IsIntConstant()) { |
Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3097 | locations->AddTemp(Location::RequiresRegister()); |
| 3098 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3099 | break; |
| 3100 | } |
| 3101 | case Primitive::kPrimLong: { |
| 3102 | InvokeRuntimeCallingConvention calling_convention; |
| 3103 | locations->SetInAt(0, Location::RegisterPairLocation( |
| 3104 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); |
| 3105 | locations->SetInAt(1, Location::RegisterPairLocation( |
| 3106 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); |
| 3107 | // Runtime helper puts the result in EAX, EDX. |
| 3108 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); |
| 3109 | break; |
| 3110 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3111 | case Primitive::kPrimDouble: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3112 | case Primitive::kPrimFloat: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3113 | locations->SetInAt(0, Location::Any()); |
| 3114 | locations->SetInAt(1, Location::Any()); |
| 3115 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3116 | locations->AddTemp(Location::RegisterLocation(EAX)); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3117 | break; |
| 3118 | } |
| 3119 | |
| 3120 | default: |
Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3121 | LOG(FATAL) << "Unexpected rem type " << type; |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3122 | } |
| 3123 | } |
| 3124 | |
| 3125 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { |
| 3126 | Primitive::Type type = rem->GetResultType(); |
| 3127 | switch (type) { |
| 3128 | case Primitive::kPrimInt: |
| 3129 | case Primitive::kPrimLong: { |
| 3130 | GenerateDivRemIntegral(rem); |
| 3131 | break; |
| 3132 | } |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3133 | case Primitive::kPrimFloat: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3134 | case Primitive::kPrimDouble: { |
Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3135 | GenerateRemFP(rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3136 | break; |
| 3137 | } |
| 3138 | default: |
| 3139 | LOG(FATAL) << "Unexpected rem type " << type; |
| 3140 | } |
| 3141 | } |
| 3142 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3143 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3144 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 3145 | ? LocationSummary::kCallOnSlowPath |
| 3146 | : LocationSummary::kNoCall; |
| 3147 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3148 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3149 | case Primitive::kPrimByte: |
| 3150 | case Primitive::kPrimChar: |
| 3151 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3152 | case Primitive::kPrimInt: { |
| 3153 | locations->SetInAt(0, Location::Any()); |
| 3154 | break; |
| 3155 | } |
| 3156 | case Primitive::kPrimLong: { |
| 3157 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
| 3158 | if (!instruction->IsConstant()) { |
| 3159 | locations->AddTemp(Location::RequiresRegister()); |
| 3160 | } |
| 3161 | break; |
| 3162 | } |
| 3163 | default: |
| 3164 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); |
| 3165 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3166 | if (instruction->HasUses()) { |
| 3167 | locations->SetOut(Location::SameAsFirstInput()); |
| 3168 | } |
| 3169 | } |
| 3170 | |
| 3171 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 3172 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3173 | codegen_->AddSlowPath(slow_path); |
| 3174 | |
| 3175 | LocationSummary* locations = instruction->GetLocations(); |
| 3176 | Location value = locations->InAt(0); |
| 3177 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3178 | switch (instruction->GetType()) { |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3179 | case Primitive::kPrimByte: |
| 3180 | case Primitive::kPrimChar: |
| 3181 | case Primitive::kPrimShort: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3182 | case Primitive::kPrimInt: { |
| 3183 | if (value.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3184 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3185 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3186 | } else if (value.IsStackSlot()) { |
| 3187 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); |
| 3188 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3189 | } else { |
| 3190 | DCHECK(value.IsConstant()) << value; |
| 3191 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { |
| 3192 | __ jmp(slow_path->GetEntryLabel()); |
| 3193 | } |
| 3194 | } |
| 3195 | break; |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3196 | } |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3197 | case Primitive::kPrimLong: { |
| 3198 | if (value.IsRegisterPair()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3199 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3200 | __ movl(temp, value.AsRegisterPairLow<Register>()); |
| 3201 | __ orl(temp, value.AsRegisterPairHigh<Register>()); |
| 3202 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 3203 | } else { |
| 3204 | DCHECK(value.IsConstant()) << value; |
| 3205 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { |
| 3206 | __ jmp(slow_path->GetEntryLabel()); |
| 3207 | } |
| 3208 | } |
| 3209 | break; |
| 3210 | } |
| 3211 | default: |
| 3212 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3213 | } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3216 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { |
| 3217 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3218 | |
| 3219 | LocationSummary* locations = |
| 3220 | new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall); |
| 3221 | |
| 3222 | switch (op->GetResultType()) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3223 | case Primitive::kPrimInt: |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3224 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3225 | // Can't have Location::Any() and output SameAsFirstInput() |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3226 | locations->SetInAt(0, Location::RequiresRegister()); |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3227 | // The shift count needs to be in CL or a constant. |
| 3228 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3229 | locations->SetOut(Location::SameAsFirstInput()); |
| 3230 | break; |
| 3231 | } |
| 3232 | default: |
| 3233 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { |
| 3238 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); |
| 3239 | |
| 3240 | LocationSummary* locations = op->GetLocations(); |
| 3241 | Location first = locations->InAt(0); |
| 3242 | Location second = locations->InAt(1); |
| 3243 | DCHECK(first.Equals(locations->Out())); |
| 3244 | |
| 3245 | switch (op->GetResultType()) { |
| 3246 | case Primitive::kPrimInt: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3247 | DCHECK(first.IsRegister()); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3248 | Register first_reg = first.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3249 | if (second.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3250 | Register second_reg = second.AsRegister<Register>(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3251 | DCHECK_EQ(ECX, second_reg); |
| 3252 | if (op->IsShl()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3253 | __ shll(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3254 | } else if (op->IsShr()) { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3255 | __ sarl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3256 | } else { |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3257 | __ shrl(first_reg, second_reg); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3258 | } |
| 3259 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3260 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftValue; |
| 3261 | if (shift == 0) { |
| 3262 | return; |
| 3263 | } |
| 3264 | Immediate imm(shift); |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3265 | if (op->IsShl()) { |
| 3266 | __ shll(first_reg, imm); |
| 3267 | } else if (op->IsShr()) { |
| 3268 | __ sarl(first_reg, imm); |
| 3269 | } else { |
| 3270 | __ shrl(first_reg, imm); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3271 | } |
| 3272 | } |
| 3273 | break; |
| 3274 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3275 | case Primitive::kPrimLong: { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3276 | if (second.IsRegister()) { |
| 3277 | Register second_reg = second.AsRegister<Register>(); |
| 3278 | DCHECK_EQ(ECX, second_reg); |
| 3279 | if (op->IsShl()) { |
| 3280 | GenerateShlLong(first, second_reg); |
| 3281 | } else if (op->IsShr()) { |
| 3282 | GenerateShrLong(first, second_reg); |
| 3283 | } else { |
| 3284 | GenerateUShrLong(first, second_reg); |
| 3285 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3286 | } else { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3287 | // Shift by a constant. |
| 3288 | int shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftValue; |
| 3289 | // Nothing to do if the shift is 0, as the input is already the output. |
| 3290 | if (shift != 0) { |
| 3291 | if (op->IsShl()) { |
| 3292 | GenerateShlLong(first, shift); |
| 3293 | } else if (op->IsShr()) { |
| 3294 | GenerateShrLong(first, shift); |
| 3295 | } else { |
| 3296 | GenerateUShrLong(first, shift); |
| 3297 | } |
| 3298 | } |
Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 3299 | } |
| 3300 | break; |
| 3301 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3302 | default: |
| 3303 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); |
| 3304 | } |
| 3305 | } |
| 3306 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3307 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { |
| 3308 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3309 | Register high = loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 3310 | if (shift == 1) { |
| 3311 | // This is just an addition. |
| 3312 | __ addl(low, low); |
| 3313 | __ adcl(high, high); |
| 3314 | } else if (shift == 32) { |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3315 | // Shift by 32 is easy. High gets low, and low gets 0. |
| 3316 | codegen_->EmitParallelMoves( |
| 3317 | loc.ToLow(), |
| 3318 | loc.ToHigh(), |
| 3319 | Primitive::kPrimInt, |
| 3320 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3321 | loc.ToLow(), |
| 3322 | Primitive::kPrimInt); |
| 3323 | } else if (shift > 32) { |
| 3324 | // Low part becomes 0. High part is low part << (shift-32). |
| 3325 | __ movl(high, low); |
| 3326 | __ shll(high, Immediate(shift - 32)); |
| 3327 | __ xorl(low, low); |
| 3328 | } else { |
| 3329 | // Between 1 and 31. |
| 3330 | __ shld(high, low, Immediate(shift)); |
| 3331 | __ shll(low, Immediate(shift)); |
| 3332 | } |
| 3333 | } |
| 3334 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3335 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3336 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3337 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); |
| 3338 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); |
| 3339 | __ testl(shifter, Immediate(32)); |
| 3340 | __ j(kEqual, &done); |
| 3341 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); |
| 3342 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); |
| 3343 | __ Bind(&done); |
| 3344 | } |
| 3345 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3346 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { |
| 3347 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3348 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3349 | if (shift == 32) { |
| 3350 | // Need to copy the sign. |
| 3351 | DCHECK_NE(low, high); |
| 3352 | __ movl(low, high); |
| 3353 | __ sarl(high, Immediate(31)); |
| 3354 | } else if (shift > 32) { |
| 3355 | DCHECK_NE(low, high); |
| 3356 | // High part becomes sign. Low part is shifted by shift - 32. |
| 3357 | __ movl(low, high); |
| 3358 | __ sarl(high, Immediate(31)); |
| 3359 | __ sarl(low, Immediate(shift - 32)); |
| 3360 | } else { |
| 3361 | // Between 1 and 31. |
| 3362 | __ shrd(low, high, Immediate(shift)); |
| 3363 | __ sarl(high, Immediate(shift)); |
| 3364 | } |
| 3365 | } |
| 3366 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3367 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3368 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3369 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3370 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3371 | __ testl(shifter, Immediate(32)); |
| 3372 | __ j(kEqual, &done); |
| 3373 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3374 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); |
| 3375 | __ Bind(&done); |
| 3376 | } |
| 3377 | |
Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 3378 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { |
| 3379 | Register low = loc.AsRegisterPairLow<Register>(); |
| 3380 | Register high = loc.AsRegisterPairHigh<Register>(); |
| 3381 | if (shift == 32) { |
| 3382 | // Shift by 32 is easy. Low gets high, and high gets 0. |
| 3383 | codegen_->EmitParallelMoves( |
| 3384 | loc.ToHigh(), |
| 3385 | loc.ToLow(), |
| 3386 | Primitive::kPrimInt, |
| 3387 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), |
| 3388 | loc.ToHigh(), |
| 3389 | Primitive::kPrimInt); |
| 3390 | } else if (shift > 32) { |
| 3391 | // Low part is high >> (shift - 32). High part becomes 0. |
| 3392 | __ movl(low, high); |
| 3393 | __ shrl(low, Immediate(shift - 32)); |
| 3394 | __ xorl(high, high); |
| 3395 | } else { |
| 3396 | // Between 1 and 31. |
| 3397 | __ shrd(low, high, Immediate(shift)); |
| 3398 | __ shrl(high, Immediate(shift)); |
| 3399 | } |
| 3400 | } |
| 3401 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3402 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3403 | NearLabel done; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3404 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); |
| 3405 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); |
| 3406 | __ testl(shifter, Immediate(32)); |
| 3407 | __ j(kEqual, &done); |
| 3408 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); |
| 3409 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); |
| 3410 | __ Bind(&done); |
| 3411 | } |
| 3412 | |
| 3413 | void LocationsBuilderX86::VisitShl(HShl* shl) { |
| 3414 | HandleShift(shl); |
| 3415 | } |
| 3416 | |
| 3417 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { |
| 3418 | HandleShift(shl); |
| 3419 | } |
| 3420 | |
| 3421 | void LocationsBuilderX86::VisitShr(HShr* shr) { |
| 3422 | HandleShift(shr); |
| 3423 | } |
| 3424 | |
| 3425 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { |
| 3426 | HandleShift(shr); |
| 3427 | } |
| 3428 | |
| 3429 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { |
| 3430 | HandleShift(ushr); |
| 3431 | } |
| 3432 | |
| 3433 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { |
| 3434 | HandleShift(ushr); |
| 3435 | } |
| 3436 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3437 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3438 | LocationSummary* locations = |
| 3439 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3440 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3441 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3442 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3443 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { |
| 3447 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3448 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3449 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3450 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3451 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3452 | instruction, |
| 3453 | instruction->GetDexPc(), |
| 3454 | nullptr); |
Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 3455 | DCHECK(!codegen_->IsLeafMethod()); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3456 | } |
| 3457 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3458 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { |
| 3459 | LocationSummary* locations = |
| 3460 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 3461 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 3462 | InvokeRuntimeCallingConvention calling_convention; |
| 3463 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 3464 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3465 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { |
| 3469 | InvokeRuntimeCallingConvention calling_convention; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3470 | __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex())); |
| 3471 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3472 | // Note: if heap poisoning is enabled, the entry point takes cares |
| 3473 | // of poisoning the reference. |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3474 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), |
| 3475 | instruction, |
| 3476 | instruction->GetDexPc(), |
| 3477 | nullptr); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3478 | DCHECK(!codegen_->IsLeafMethod()); |
| 3479 | } |
| 3480 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3481 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3482 | LocationSummary* locations = |
| 3483 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3484 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); |
| 3485 | if (location.IsStackSlot()) { |
| 3486 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
| 3487 | } else if (location.IsDoubleStackSlot()) { |
| 3488 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3489 | } |
Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 3490 | locations->SetOut(location); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3491 | } |
| 3492 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3493 | void InstructionCodeGeneratorX86::VisitParameterValue( |
| 3494 | HParameterValue* instruction ATTRIBUTE_UNUSED) { |
| 3495 | } |
| 3496 | |
| 3497 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { |
| 3498 | LocationSummary* locations = |
| 3499 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3500 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); |
| 3501 | } |
| 3502 | |
| 3503 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3504 | } |
| 3505 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3506 | void LocationsBuilderX86::VisitNot(HNot* not_) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3507 | LocationSummary* locations = |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3508 | new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3509 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3510 | locations->SetOut(Location::SameAsFirstInput()); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3511 | } |
| 3512 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3513 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { |
| 3514 | LocationSummary* locations = not_->GetLocations(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3515 | Location in = locations->InAt(0); |
Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3516 | Location out = locations->Out(); |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3517 | DCHECK(in.Equals(out)); |
Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 3518 | switch (not_->GetResultType()) { |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3519 | case Primitive::kPrimInt: |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3520 | __ notl(out.AsRegister<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3521 | break; |
| 3522 | |
| 3523 | case Primitive::kPrimLong: |
Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 3524 | __ notl(out.AsRegisterPairLow<Register>()); |
| 3525 | __ notl(out.AsRegisterPairHigh<Register>()); |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3526 | break; |
| 3527 | |
| 3528 | default: |
| 3529 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); |
| 3530 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3531 | } |
| 3532 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3533 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { |
| 3534 | LocationSummary* locations = |
| 3535 | new (GetGraph()->GetArena()) LocationSummary(bool_not, LocationSummary::kNoCall); |
| 3536 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3537 | locations->SetOut(Location::SameAsFirstInput()); |
| 3538 | } |
| 3539 | |
| 3540 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3541 | LocationSummary* locations = bool_not->GetLocations(); |
| 3542 | Location in = locations->InAt(0); |
| 3543 | Location out = locations->Out(); |
| 3544 | DCHECK(in.Equals(out)); |
| 3545 | __ xorl(out.AsRegister<Register>(), Immediate(1)); |
| 3546 | } |
| 3547 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3548 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3549 | LocationSummary* locations = |
| 3550 | new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3551 | switch (compare->InputAt(0)->GetType()) { |
| 3552 | case Primitive::kPrimLong: { |
| 3553 | locations->SetInAt(0, Location::RequiresRegister()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3554 | locations->SetInAt(1, Location::Any()); |
| 3555 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 3556 | break; |
| 3557 | } |
| 3558 | case Primitive::kPrimFloat: |
| 3559 | case Primitive::kPrimDouble: { |
| 3560 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 3561 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 3562 | locations->SetOut(Location::RequiresRegister()); |
| 3563 | break; |
| 3564 | } |
| 3565 | default: |
| 3566 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
| 3567 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3568 | } |
| 3569 | |
| 3570 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3571 | LocationSummary* locations = compare->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3572 | Register out = locations->Out().AsRegister<Register>(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3573 | Location left = locations->InAt(0); |
| 3574 | Location right = locations->InAt(1); |
| 3575 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3576 | NearLabel less, greater, done; |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3577 | switch (compare->InputAt(0)->GetType()) { |
| 3578 | case Primitive::kPrimLong: { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3579 | Register left_low = left.AsRegisterPairLow<Register>(); |
| 3580 | Register left_high = left.AsRegisterPairHigh<Register>(); |
| 3581 | int32_t val_low = 0; |
| 3582 | int32_t val_high = 0; |
| 3583 | bool right_is_const = false; |
| 3584 | |
| 3585 | if (right.IsConstant()) { |
| 3586 | DCHECK(right.GetConstant()->IsLongConstant()); |
| 3587 | right_is_const = true; |
| 3588 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); |
| 3589 | val_low = Low32Bits(val); |
| 3590 | val_high = High32Bits(val); |
| 3591 | } |
| 3592 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3593 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3594 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3595 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3596 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3597 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3598 | DCHECK(right_is_const) << right; |
| 3599 | if (val_high == 0) { |
| 3600 | __ testl(left_high, left_high); |
| 3601 | } else { |
| 3602 | __ cmpl(left_high, Immediate(val_high)); |
| 3603 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3604 | } |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3605 | __ j(kLess, &less); // Signed compare. |
| 3606 | __ j(kGreater, &greater); // Signed compare. |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3607 | if (right.IsRegisterPair()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3608 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3609 | } else if (right.IsDoubleStackSlot()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3610 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3611 | } else { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 3612 | DCHECK(right_is_const) << right; |
| 3613 | if (val_low == 0) { |
| 3614 | __ testl(left_low, left_low); |
| 3615 | } else { |
| 3616 | __ cmpl(left_low, Immediate(val_low)); |
| 3617 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3618 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3619 | break; |
| 3620 | } |
| 3621 | case Primitive::kPrimFloat: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3622 | __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3623 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
| 3624 | break; |
| 3625 | } |
| 3626 | case Primitive::kPrimDouble: { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3627 | __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>()); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3628 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3629 | break; |
| 3630 | } |
| 3631 | default: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3632 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3633 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3634 | __ movl(out, Immediate(0)); |
| 3635 | __ j(kEqual, &done); |
| 3636 | __ j(kBelow, &less); // kBelow is for CF (unsigned & floats). |
| 3637 | |
| 3638 | __ Bind(&greater); |
| 3639 | __ movl(out, Immediate(1)); |
| 3640 | __ jmp(&done); |
| 3641 | |
| 3642 | __ Bind(&less); |
| 3643 | __ movl(out, Immediate(-1)); |
| 3644 | |
| 3645 | __ Bind(&done); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3646 | } |
| 3647 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3648 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3649 | LocationSummary* locations = |
| 3650 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 3651 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 3652 | locations->SetInAt(i, Location::Any()); |
| 3653 | } |
| 3654 | locations->SetOut(Location::Any()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3655 | } |
| 3656 | |
| 3657 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3658 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 3659 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3660 | } |
| 3661 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3662 | void InstructionCodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { |
| 3663 | /* |
| 3664 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. |
| 3665 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. |
| 3666 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. |
| 3667 | */ |
| 3668 | switch (kind) { |
| 3669 | case MemBarrierKind::kAnyAny: { |
| 3670 | __ mfence(); |
| 3671 | break; |
| 3672 | } |
| 3673 | case MemBarrierKind::kAnyStore: |
| 3674 | case MemBarrierKind::kLoadAny: |
| 3675 | case MemBarrierKind::kStoreStore: { |
| 3676 | // nop |
| 3677 | break; |
| 3678 | } |
| 3679 | default: |
| 3680 | LOG(FATAL) << "Unexpected memory barrier " << kind; |
Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 3681 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3682 | } |
| 3683 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3684 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3685 | void CodeGeneratorX86::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) { |
| 3686 | Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp. |
| 3687 | switch (invoke->GetMethodLoadKind()) { |
| 3688 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: |
| 3689 | // temp = thread->string_init_entrypoint |
| 3690 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(invoke->GetStringInitOffset())); |
| 3691 | break; |
| 3692 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: |
| 3693 | callee_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3694 | break; |
| 3695 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress: |
| 3696 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); |
| 3697 | break; |
| 3698 | case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup: |
| 3699 | __ movl(temp.AsRegister<Register>(), Immediate(0)); // Placeholder. |
| 3700 | method_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3701 | __ Bind(&method_patches_.back().label); // Bind the label at the end of the "movl" insn. |
| 3702 | break; |
| 3703 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: |
| 3704 | // TODO: Implement this type. For the moment, we fall back to kDexCacheViaMethod. |
| 3705 | FALLTHROUGH_INTENDED; |
| 3706 | case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: { |
| 3707 | Location current_method = invoke->GetLocations()->InAt(invoke->GetCurrentMethodInputIndex()); |
| 3708 | Register method_reg; |
| 3709 | Register reg = temp.AsRegister<Register>(); |
| 3710 | if (current_method.IsRegister()) { |
| 3711 | method_reg = current_method.AsRegister<Register>(); |
| 3712 | } else { |
| 3713 | DCHECK(IsBaseline() || invoke->GetLocations()->Intrinsified()); |
| 3714 | DCHECK(!current_method.IsValid()); |
| 3715 | method_reg = reg; |
| 3716 | __ movl(reg, Address(ESP, kCurrentMethodStackOffset)); |
| 3717 | } |
| 3718 | // temp = temp->dex_cache_resolved_methods_; |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 3719 | __ movl(reg, Address(method_reg, |
| 3720 | ArtMethod::DexCacheResolvedMethodsOffset(kX86PointerSize).Int32Value())); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3721 | // temp = temp[index_in_cache] |
| 3722 | uint32_t index_in_cache = invoke->GetTargetMethod().dex_method_index; |
| 3723 | __ movl(reg, Address(reg, CodeGenerator::GetCachePointerOffset(index_in_cache))); |
| 3724 | break; |
Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 3725 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | switch (invoke->GetCodePtrLocation()) { |
| 3729 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: |
| 3730 | __ call(GetFrameEntryLabel()); |
| 3731 | break; |
| 3732 | case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative: { |
| 3733 | relative_call_patches_.emplace_back(invoke->GetTargetMethod()); |
| 3734 | Label* label = &relative_call_patches_.back().label; |
| 3735 | __ call(label); // Bind to the patch label, override at link time. |
| 3736 | __ Bind(label); // Bind the label at the end of the "call" insn. |
| 3737 | break; |
| 3738 | } |
| 3739 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup: |
| 3740 | case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect: |
| 3741 | // For direct code, we actually prefer to call via the code pointer from ArtMethod*. |
| 3742 | // (Though the direct CALL ptr16:32 is available for consideration). |
| 3743 | FALLTHROUGH_INTENDED; |
| 3744 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: |
| 3745 | // (callee_method + offset_of_quick_compiled_code)() |
| 3746 | __ call(Address(callee_method.AsRegister<Register>(), |
| 3747 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( |
| 3748 | kX86WordSize).Int32Value())); |
| 3749 | break; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | DCHECK(!IsLeafMethod()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3753 | } |
| 3754 | |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 3755 | void CodeGeneratorX86::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_in) { |
| 3756 | Register temp = temp_in.AsRegister<Register>(); |
| 3757 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( |
| 3758 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); |
| 3759 | LocationSummary* locations = invoke->GetLocations(); |
| 3760 | Location receiver = locations->InAt(0); |
| 3761 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 3762 | // temp = object->GetClass(); |
| 3763 | DCHECK(receiver.IsRegister()); |
| 3764 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); |
| 3765 | MaybeRecordImplicitNullCheck(invoke); |
| 3766 | __ MaybeUnpoisonHeapReference(temp); |
| 3767 | // temp = temp->GetMethodAt(method_offset); |
| 3768 | __ movl(temp, Address(temp, method_offset)); |
| 3769 | // call temp->GetEntryPoint(); |
| 3770 | __ call(Address( |
| 3771 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value())); |
| 3772 | } |
| 3773 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3774 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) { |
| 3775 | DCHECK(linker_patches->empty()); |
| 3776 | linker_patches->reserve(method_patches_.size() + relative_call_patches_.size()); |
| 3777 | for (const MethodPatchInfo<Label>& info : method_patches_) { |
| 3778 | // The label points to the end of the "movl" insn but the literal offset for method |
| 3779 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3780 | uint32_t literal_offset = info.label.Position() - 4; |
| 3781 | linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset, |
| 3782 | info.target_method.dex_file, |
| 3783 | info.target_method.dex_method_index)); |
| 3784 | } |
| 3785 | for (const MethodPatchInfo<Label>& info : relative_call_patches_) { |
| 3786 | // The label points to the end of the "call" insn but the literal offset for method |
| 3787 | // patch x86 needs to point to the embedded constant which occupies the last 4 bytes. |
| 3788 | uint32_t literal_offset = info.label.Position() - 4; |
| 3789 | linker_patches->push_back(LinkerPatch::RelativeCodePatch(literal_offset, |
| 3790 | info.target_method.dex_file, |
| 3791 | info.target_method.dex_method_index)); |
| 3792 | } |
| 3793 | } |
| 3794 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3795 | void CodeGeneratorX86::MarkGCCard(Register temp, |
| 3796 | Register card, |
| 3797 | Register object, |
| 3798 | Register value, |
| 3799 | bool value_can_be_null) { |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3800 | NearLabel is_null; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3801 | if (value_can_be_null) { |
| 3802 | __ testl(value, value); |
| 3803 | __ j(kEqual, &is_null); |
| 3804 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3805 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value())); |
| 3806 | __ movl(temp, object); |
| 3807 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); |
Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 3808 | __ movb(Address(temp, card, TIMES_1, 0), |
| 3809 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3810 | if (value_can_be_null) { |
| 3811 | __ Bind(&is_null); |
| 3812 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 3813 | } |
| 3814 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3815 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3816 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3817 | LocationSummary* locations = |
| 3818 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 3819 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3820 | |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3821 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 3822 | locations->SetOut(Location::RequiresFpuRegister()); |
| 3823 | } else { |
| 3824 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 3825 | // the object's location. |
| 3826 | locations->SetOut(Location::RequiresRegister(), |
| 3827 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 3828 | : Location::kNoOutputOverlap); |
| 3829 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3830 | |
| 3831 | if (field_info.IsVolatile() && (field_info.GetFieldType() == Primitive::kPrimLong)) { |
| 3832 | // Long values can be loaded atomically into an XMM using movsd. |
| 3833 | // So we use an XMM register as a temp to achieve atomicity (first load the temp into the XMM |
| 3834 | // and then copy the XMM into the output 32bits at a time). |
| 3835 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3836 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3837 | } |
| 3838 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3839 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, |
| 3840 | const FieldInfo& field_info) { |
| 3841 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3842 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3843 | LocationSummary* locations = instruction->GetLocations(); |
| 3844 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3845 | Location out = locations->Out(); |
| 3846 | bool is_volatile = field_info.IsVolatile(); |
| 3847 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3848 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
| 3849 | |
| 3850 | switch (field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3851 | case Primitive::kPrimBoolean: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3852 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3853 | break; |
| 3854 | } |
| 3855 | |
| 3856 | case Primitive::kPrimByte: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3857 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3858 | break; |
| 3859 | } |
| 3860 | |
| 3861 | case Primitive::kPrimShort: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3862 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3863 | break; |
| 3864 | } |
| 3865 | |
| 3866 | case Primitive::kPrimChar: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3867 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3868 | break; |
| 3869 | } |
| 3870 | |
| 3871 | case Primitive::kPrimInt: |
| 3872 | case Primitive::kPrimNot: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3873 | __ movl(out.AsRegister<Register>(), Address(base, offset)); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3874 | break; |
| 3875 | } |
| 3876 | |
| 3877 | case Primitive::kPrimLong: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3878 | if (is_volatile) { |
| 3879 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 3880 | __ movsd(temp, Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3881 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3882 | __ movd(out.AsRegisterPairLow<Register>(), temp); |
| 3883 | __ psrlq(temp, Immediate(32)); |
| 3884 | __ movd(out.AsRegisterPairHigh<Register>(), temp); |
| 3885 | } else { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3886 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3887 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3888 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3889 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); |
| 3890 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3891 | break; |
| 3892 | } |
| 3893 | |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3894 | case Primitive::kPrimFloat: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3895 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3896 | break; |
| 3897 | } |
| 3898 | |
| 3899 | case Primitive::kPrimDouble: { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3900 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); |
Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 3901 | break; |
| 3902 | } |
| 3903 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3904 | case Primitive::kPrimVoid: |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3905 | LOG(FATAL) << "Unreachable type " << field_type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 3906 | UNREACHABLE(); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 3907 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3908 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3909 | // Longs are handled in the switch. |
| 3910 | if (field_type != Primitive::kPrimLong) { |
| 3911 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 3912 | } |
| 3913 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3914 | if (is_volatile) { |
| 3915 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 3916 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3917 | |
| 3918 | if (field_type == Primitive::kPrimNot) { |
| 3919 | __ MaybeUnpoisonHeapReference(out.AsRegister<Register>()); |
| 3920 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { |
| 3924 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3925 | |
| 3926 | LocationSummary* locations = |
| 3927 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 3928 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3929 | bool is_volatile = field_info.IsVolatile(); |
| 3930 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3931 | bool is_byte_type = (field_type == Primitive::kPrimBoolean) |
| 3932 | || (field_type == Primitive::kPrimByte); |
| 3933 | |
| 3934 | // The register allocator does not support multiple |
| 3935 | // inputs that die at entry with one in a specific register. |
| 3936 | if (is_byte_type) { |
| 3937 | // Ensure the value is in a byte register. |
| 3938 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 3939 | } else if (Primitive::IsFloatingPointType(field_type)) { |
| 3940 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3941 | } else { |
| 3942 | locations->SetInAt(1, Location::RequiresRegister()); |
| 3943 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3944 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3945 | // Temporary registers for the write barrier. |
| 3946 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3947 | // Ensure the card is in a byte register. |
| 3948 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 3949 | } else if (is_volatile && (field_type == Primitive::kPrimLong)) { |
| 3950 | // 64bits value can be atomically written to an address with movsd and an XMM register. |
| 3951 | // We need two XMM registers because there's no easier way to (bit) copy a register pair |
| 3952 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). |
| 3953 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the |
| 3954 | // isolated cases when we need this it isn't worth adding the extra complexity. |
| 3955 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3956 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 3957 | } |
| 3958 | } |
| 3959 | |
| 3960 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 3961 | const FieldInfo& field_info, |
| 3962 | bool value_can_be_null) { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3963 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); |
| 3964 | |
| 3965 | LocationSummary* locations = instruction->GetLocations(); |
| 3966 | Register base = locations->InAt(0).AsRegister<Register>(); |
| 3967 | Location value = locations->InAt(1); |
| 3968 | bool is_volatile = field_info.IsVolatile(); |
| 3969 | Primitive::Type field_type = field_info.GetFieldType(); |
| 3970 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3971 | bool needs_write_barrier = |
| 3972 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 3973 | |
| 3974 | if (is_volatile) { |
| 3975 | GenerateMemoryBarrier(MemBarrierKind::kAnyStore); |
| 3976 | } |
| 3977 | |
| 3978 | switch (field_type) { |
| 3979 | case Primitive::kPrimBoolean: |
| 3980 | case Primitive::kPrimByte: { |
| 3981 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); |
| 3982 | break; |
| 3983 | } |
| 3984 | |
| 3985 | case Primitive::kPrimShort: |
| 3986 | case Primitive::kPrimChar: { |
| 3987 | __ movw(Address(base, offset), value.AsRegister<Register>()); |
| 3988 | break; |
| 3989 | } |
| 3990 | |
| 3991 | case Primitive::kPrimInt: |
| 3992 | case Primitive::kPrimNot: { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3993 | if (kPoisonHeapReferences && needs_write_barrier) { |
| 3994 | // Note that in the case where `value` is a null reference, |
| 3995 | // we do not enter this block, as the reference does not |
| 3996 | // need poisoning. |
| 3997 | DCHECK_EQ(field_type, Primitive::kPrimNot); |
| 3998 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 3999 | __ movl(temp, value.AsRegister<Register>()); |
| 4000 | __ PoisonHeapReference(temp); |
| 4001 | __ movl(Address(base, offset), temp); |
| 4002 | } else { |
| 4003 | __ movl(Address(base, offset), value.AsRegister<Register>()); |
| 4004 | } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4005 | break; |
| 4006 | } |
| 4007 | |
| 4008 | case Primitive::kPrimLong: { |
| 4009 | if (is_volatile) { |
| 4010 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 4011 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 4012 | __ movd(temp1, value.AsRegisterPairLow<Register>()); |
| 4013 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); |
| 4014 | __ punpckldq(temp1, temp2); |
| 4015 | __ movsd(Address(base, offset), temp1); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4016 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4017 | } else { |
| 4018 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4019 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4020 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); |
| 4021 | } |
| 4022 | break; |
| 4023 | } |
| 4024 | |
| 4025 | case Primitive::kPrimFloat: { |
| 4026 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4027 | break; |
| 4028 | } |
| 4029 | |
| 4030 | case Primitive::kPrimDouble: { |
| 4031 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); |
| 4032 | break; |
| 4033 | } |
| 4034 | |
| 4035 | case Primitive::kPrimVoid: |
| 4036 | LOG(FATAL) << "Unreachable type " << field_type; |
| 4037 | UNREACHABLE(); |
| 4038 | } |
| 4039 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4040 | // Longs are handled in the switch. |
| 4041 | if (field_type != Primitive::kPrimLong) { |
| 4042 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4043 | } |
| 4044 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4045 | if (needs_write_barrier) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4046 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4047 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4048 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4049 | } |
| 4050 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4051 | if (is_volatile) { |
| 4052 | GenerateMemoryBarrier(MemBarrierKind::kAnyAny); |
| 4053 | } |
| 4054 | } |
| 4055 | |
| 4056 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4057 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4058 | } |
| 4059 | |
| 4060 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { |
| 4061 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4062 | } |
| 4063 | |
| 4064 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
| 4065 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4066 | } |
| 4067 | |
| 4068 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4069 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
| 4073 | HandleFieldSet(instruction, instruction->GetFieldInfo()); |
| 4074 | } |
| 4075 | |
| 4076 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4077 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4081 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
| 4082 | } |
| 4083 | |
| 4084 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { |
| 4085 | HandleFieldGet(instruction, instruction->GetFieldInfo()); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4089 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4090 | ? LocationSummary::kCallOnSlowPath |
| 4091 | : LocationSummary::kNoCall; |
| 4092 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
| 4093 | Location loc = codegen_->IsImplicitNullCheckAllowed(instruction) |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4094 | ? Location::RequiresRegister() |
| 4095 | : Location::Any(); |
| 4096 | locations->SetInAt(0, loc); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4097 | if (instruction->HasUses()) { |
| 4098 | locations->SetOut(Location::SameAsFirstInput()); |
| 4099 | } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4100 | } |
| 4101 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4102 | void InstructionCodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4103 | if (codegen_->CanMoveNullCheckToUser(instruction)) { |
| 4104 | return; |
| 4105 | } |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4106 | LocationSummary* locations = instruction->GetLocations(); |
| 4107 | Location obj = locations->InAt(0); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4108 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4109 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); |
| 4110 | codegen_->RecordPcInfo(instruction, instruction->GetDexPc()); |
| 4111 | } |
| 4112 | |
| 4113 | void InstructionCodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4114 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4115 | codegen_->AddSlowPath(slow_path); |
| 4116 | |
| 4117 | LocationSummary* locations = instruction->GetLocations(); |
| 4118 | Location obj = locations->InAt(0); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4119 | |
| 4120 | if (obj.IsRegister()) { |
Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 4121 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4122 | } else if (obj.IsStackSlot()) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4123 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4124 | } else { |
| 4125 | DCHECK(obj.IsConstant()) << obj; |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4126 | DCHECK(obj.GetConstant()->IsNullConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4127 | __ jmp(slow_path->GetEntryLabel()); |
| 4128 | return; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4129 | } |
| 4130 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4131 | } |
| 4132 | |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4133 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4134 | if (codegen_->IsImplicitNullCheckAllowed(instruction)) { |
Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 4135 | GenerateImplicitNullCheck(instruction); |
| 4136 | } else { |
| 4137 | GenerateExplicitNullCheck(instruction); |
| 4138 | } |
| 4139 | } |
| 4140 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4141 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4142 | LocationSummary* locations = |
| 4143 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4144 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4145 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 4146 | if (Primitive::IsFloatingPointType(instruction->GetType())) { |
| 4147 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 4148 | } else { |
| 4149 | // The output overlaps in case of long: we don't want the low move to overwrite |
| 4150 | // the array's location. |
| 4151 | locations->SetOut(Location::RequiresRegister(), |
| 4152 | (instruction->GetType() == Primitive::kPrimLong) ? Location::kOutputOverlap |
| 4153 | : Location::kNoOutputOverlap); |
| 4154 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { |
| 4158 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4159 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4160 | Location index = locations->InAt(1); |
| 4161 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4162 | Primitive::Type type = instruction->GetType(); |
| 4163 | switch (type) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4164 | case Primitive::kPrimBoolean: { |
| 4165 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4166 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4167 | if (index.IsConstant()) { |
| 4168 | __ movzxb(out, Address(obj, |
| 4169 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4170 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4171 | __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4172 | } |
| 4173 | break; |
| 4174 | } |
| 4175 | |
| 4176 | case Primitive::kPrimByte: { |
| 4177 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4178 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4179 | if (index.IsConstant()) { |
| 4180 | __ movsxb(out, Address(obj, |
| 4181 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset)); |
| 4182 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4183 | __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4184 | } |
| 4185 | break; |
| 4186 | } |
| 4187 | |
| 4188 | case Primitive::kPrimShort: { |
| 4189 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4190 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4191 | if (index.IsConstant()) { |
| 4192 | __ movsxw(out, Address(obj, |
| 4193 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4194 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4195 | __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4196 | } |
| 4197 | break; |
| 4198 | } |
| 4199 | |
| 4200 | case Primitive::kPrimChar: { |
| 4201 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4202 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4203 | if (index.IsConstant()) { |
| 4204 | __ movzxw(out, Address(obj, |
| 4205 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset)); |
| 4206 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4207 | __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4208 | } |
| 4209 | break; |
| 4210 | } |
| 4211 | |
| 4212 | case Primitive::kPrimInt: |
| 4213 | case Primitive::kPrimNot: { |
| 4214 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4215 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4216 | if (index.IsConstant()) { |
| 4217 | __ movl(out, Address(obj, |
| 4218 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4219 | } else { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4220 | __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4221 | } |
| 4222 | break; |
| 4223 | } |
| 4224 | |
| 4225 | case Primitive::kPrimLong: { |
| 4226 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4227 | Location out = locations->Out(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4228 | DCHECK_NE(obj, out.AsRegisterPairLow<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4229 | if (index.IsConstant()) { |
| 4230 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4231 | __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4232 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4233 | __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4234 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4235 | __ movl(out.AsRegisterPairLow<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4236 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4237 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4238 | __ movl(out.AsRegisterPairHigh<Register>(), |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4239 | Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4240 | } |
| 4241 | break; |
| 4242 | } |
| 4243 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4244 | case Primitive::kPrimFloat: { |
| 4245 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4246 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4247 | if (index.IsConstant()) { |
| 4248 | __ movss(out, Address(obj, |
| 4249 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset)); |
| 4250 | } else { |
| 4251 | __ movss(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset)); |
| 4252 | } |
| 4253 | break; |
| 4254 | } |
| 4255 | |
| 4256 | case Primitive::kPrimDouble: { |
| 4257 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4258 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 4259 | if (index.IsConstant()) { |
| 4260 | __ movsd(out, Address(obj, |
| 4261 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset)); |
| 4262 | } else { |
| 4263 | __ movsd(out, Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset)); |
| 4264 | } |
| 4265 | break; |
| 4266 | } |
| 4267 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4268 | case Primitive::kPrimVoid: |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4269 | LOG(FATAL) << "Unreachable type " << type; |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4270 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4271 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4272 | |
| 4273 | if (type != Primitive::kPrimLong) { |
| 4274 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4275 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 4276 | |
| 4277 | if (type == Primitive::kPrimNot) { |
| 4278 | Register out = locations->Out().AsRegister<Register>(); |
| 4279 | __ MaybeUnpoisonHeapReference(out); |
| 4280 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4281 | } |
| 4282 | |
| 4283 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { |
Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 4284 | // This location builder might end up asking to up to four registers, which is |
| 4285 | // not currently possible for baseline. The situation in which we need four |
| 4286 | // registers cannot be met by baseline though, because it has not run any |
| 4287 | // optimization. |
| 4288 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4289 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4290 | bool needs_write_barrier = |
| 4291 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
| 4292 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4293 | bool may_need_runtime_call = instruction->NeedsTypeCheck(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4294 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4295 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
| 4296 | instruction, |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4297 | may_need_runtime_call ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4298 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4299 | bool is_byte_type = (value_type == Primitive::kPrimBoolean) |
| 4300 | || (value_type == Primitive::kPrimByte); |
| 4301 | // We need the inputs to be different than the output in case of long operation. |
| 4302 | // In case of a byte operation, the register allocator does not support multiple |
| 4303 | // inputs that die at entry with one in a specific register. |
| 4304 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4305 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 4306 | if (is_byte_type) { |
| 4307 | // Ensure the value is in a byte register. |
| 4308 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); |
| 4309 | } else if (Primitive::IsFloatingPointType(value_type)) { |
| 4310 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4311 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4312 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); |
| 4313 | } |
| 4314 | if (needs_write_barrier) { |
| 4315 | // Temporary registers for the write barrier. |
| 4316 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for ref. poisoning too. |
| 4317 | // Ensure the card is in a byte register. |
| 4318 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4319 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { |
| 4323 | LocationSummary* locations = instruction->GetLocations(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4324 | Register array = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4325 | Location index = locations->InAt(1); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4326 | Location value = locations->InAt(2); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4327 | Primitive::Type value_type = instruction->GetComponentType(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4328 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 4329 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 4330 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 4331 | bool may_need_runtime_call = locations->CanCall(); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4332 | bool needs_write_barrier = |
| 4333 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4334 | |
| 4335 | switch (value_type) { |
| 4336 | case Primitive::kPrimBoolean: |
| 4337 | case Primitive::kPrimByte: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4338 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); |
| 4339 | Address address = index.IsConstant() |
| 4340 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + offset) |
| 4341 | : Address(array, index.AsRegister<Register>(), TIMES_1, offset); |
| 4342 | if (value.IsRegister()) { |
| 4343 | __ movb(address, value.AsRegister<ByteRegister>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4344 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4345 | __ movb(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4346 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4347 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4348 | break; |
| 4349 | } |
| 4350 | |
| 4351 | case Primitive::kPrimShort: |
| 4352 | case Primitive::kPrimChar: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4353 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); |
| 4354 | Address address = index.IsConstant() |
| 4355 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + offset) |
| 4356 | : Address(array, index.AsRegister<Register>(), TIMES_2, offset); |
| 4357 | if (value.IsRegister()) { |
| 4358 | __ movw(address, value.AsRegister<Register>()); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4359 | } else { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4360 | __ movw(address, Immediate(value.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4361 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4362 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4363 | break; |
| 4364 | } |
| 4365 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4366 | case Primitive::kPrimNot: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4367 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4368 | Address address = index.IsConstant() |
| 4369 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4370 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 4371 | if (!value.IsRegister()) { |
| 4372 | // Just setting null. |
| 4373 | DCHECK(instruction->InputAt(2)->IsNullConstant()); |
| 4374 | DCHECK(value.IsConstant()) << value; |
| 4375 | __ movl(address, Immediate(0)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4376 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4377 | DCHECK(!needs_write_barrier); |
| 4378 | DCHECK(!may_need_runtime_call); |
| 4379 | break; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4380 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4381 | |
| 4382 | DCHECK(needs_write_barrier); |
| 4383 | Register register_value = value.AsRegister<Register>(); |
| 4384 | NearLabel done, not_null, do_put; |
| 4385 | SlowPathCode* slow_path = nullptr; |
| 4386 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 4387 | if (may_need_runtime_call) { |
| 4388 | slow_path = new (GetGraph()->GetArena()) ArraySetSlowPathX86(instruction); |
| 4389 | codegen_->AddSlowPath(slow_path); |
| 4390 | if (instruction->GetValueCanBeNull()) { |
| 4391 | __ testl(register_value, register_value); |
| 4392 | __ j(kNotEqual, ¬_null); |
| 4393 | __ movl(address, Immediate(0)); |
| 4394 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4395 | __ jmp(&done); |
| 4396 | __ Bind(¬_null); |
| 4397 | } |
| 4398 | |
| 4399 | __ movl(temp, Address(array, class_offset)); |
| 4400 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4401 | __ MaybeUnpoisonHeapReference(temp); |
| 4402 | __ movl(temp, Address(temp, component_offset)); |
| 4403 | // No need to poison/unpoison, we're comparing two poisoned references. |
| 4404 | __ cmpl(temp, Address(register_value, class_offset)); |
| 4405 | if (instruction->StaticTypeOfArrayIsObjectArray()) { |
| 4406 | __ j(kEqual, &do_put); |
| 4407 | __ MaybeUnpoisonHeapReference(temp); |
| 4408 | __ movl(temp, Address(temp, super_offset)); |
| 4409 | // No need to unpoison, we're comparing against null.. |
| 4410 | __ testl(temp, temp); |
| 4411 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4412 | __ Bind(&do_put); |
| 4413 | } else { |
| 4414 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4415 | } |
| 4416 | } |
| 4417 | |
| 4418 | if (kPoisonHeapReferences) { |
| 4419 | __ movl(temp, register_value); |
| 4420 | __ PoisonHeapReference(temp); |
| 4421 | __ movl(address, temp); |
| 4422 | } else { |
| 4423 | __ movl(address, register_value); |
| 4424 | } |
| 4425 | if (!may_need_runtime_call) { |
| 4426 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
| 4427 | } |
| 4428 | |
| 4429 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
| 4430 | codegen_->MarkGCCard( |
| 4431 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); |
| 4432 | __ Bind(&done); |
| 4433 | |
| 4434 | if (slow_path != nullptr) { |
| 4435 | __ Bind(slow_path->GetExitLabel()); |
| 4436 | } |
| 4437 | |
| 4438 | break; |
| 4439 | } |
| 4440 | case Primitive::kPrimInt: { |
| 4441 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); |
| 4442 | Address address = index.IsConstant() |
| 4443 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4444 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
| 4445 | if (value.IsRegister()) { |
| 4446 | __ movl(address, value.AsRegister<Register>()); |
| 4447 | } else { |
| 4448 | DCHECK(value.IsConstant()) << value; |
| 4449 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); |
| 4450 | __ movl(address, Immediate(v)); |
| 4451 | } |
| 4452 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4453 | break; |
| 4454 | } |
| 4455 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4456 | case Primitive::kPrimLong: { |
| 4457 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4458 | if (index.IsConstant()) { |
| 4459 | size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset; |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4460 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4461 | __ movl(Address(array, offset), value.AsRegisterPairLow<Register>()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4462 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4463 | __ movl(Address(array, offset + kX86WordSize), value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4464 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4465 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4466 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4467 | __ movl(Address(array, offset), Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4468 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4469 | __ movl(Address(array, offset + kX86WordSize), Immediate(High32Bits(val))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4470 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4471 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4472 | if (value.IsRegisterPair()) { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4473 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4474 | value.AsRegisterPairLow<Register>()); |
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 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4477 | value.AsRegisterPairHigh<Register>()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4478 | } else { |
Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4479 | DCHECK(value.IsConstant()); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4480 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4481 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4482 | Immediate(Low32Bits(val))); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4483 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4484 | __ movl(Address(array, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize), |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4485 | Immediate(High32Bits(val))); |
| 4486 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4487 | } |
| 4488 | break; |
| 4489 | } |
| 4490 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4491 | case Primitive::kPrimFloat: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4492 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); |
| 4493 | Address address = index.IsConstant() |
| 4494 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + offset) |
| 4495 | : Address(array, index.AsRegister<Register>(), TIMES_4, offset); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4496 | DCHECK(value.IsFpuRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4497 | __ movss(address, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4498 | break; |
| 4499 | } |
| 4500 | |
| 4501 | case Primitive::kPrimDouble: { |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4502 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); |
| 4503 | Address address = index.IsConstant() |
| 4504 | ? Address(array, (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + offset) |
| 4505 | : Address(array, index.AsRegister<Register>(), TIMES_8, offset); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4506 | DCHECK(value.IsFpuRegister()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame^] | 4507 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4508 | break; |
| 4509 | } |
| 4510 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4511 | case Primitive::kPrimVoid: |
| 4512 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 4513 | UNREACHABLE(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { |
| 4518 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 4519 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4520 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { |
| 4524 | LocationSummary* locations = instruction->GetLocations(); |
| 4525 | uint32_t offset = mirror::Array::LengthOffset().Uint32Value(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4526 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 4527 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4528 | __ movl(out, Address(obj, offset)); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4529 | codegen_->MaybeRecordImplicitNullCheck(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4533 | LocationSummary::CallKind call_kind = instruction->CanThrowIntoCatchBlock() |
| 4534 | ? LocationSummary::kCallOnSlowPath |
| 4535 | : LocationSummary::kNoCall; |
| 4536 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4537 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4538 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 4539 | if (instruction->HasUses()) { |
| 4540 | locations->SetOut(Location::SameAsFirstInput()); |
| 4541 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4542 | } |
| 4543 | |
| 4544 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { |
| 4545 | LocationSummary* locations = instruction->GetLocations(); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4546 | Location index_loc = locations->InAt(0); |
| 4547 | Location length_loc = locations->InAt(1); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4548 | SlowPathCode* slow_path = |
Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 4549 | new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(instruction); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4550 | |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4551 | if (length_loc.IsConstant()) { |
| 4552 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); |
| 4553 | if (index_loc.IsConstant()) { |
| 4554 | // BCE will remove the bounds check if we are guarenteed to pass. |
| 4555 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4556 | if (index < 0 || index >= length) { |
| 4557 | codegen_->AddSlowPath(slow_path); |
| 4558 | __ jmp(slow_path->GetEntryLabel()); |
| 4559 | } else { |
| 4560 | // Some optimization after BCE may have generated this, and we should not |
| 4561 | // generate a bounds check if it is a valid range. |
| 4562 | } |
| 4563 | return; |
| 4564 | } |
| 4565 | |
| 4566 | // We have to reverse the jump condition because the length is the constant. |
| 4567 | Register index_reg = index_loc.AsRegister<Register>(); |
| 4568 | __ cmpl(index_reg, Immediate(length)); |
| 4569 | codegen_->AddSlowPath(slow_path); |
| 4570 | __ j(kAboveEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4571 | } else { |
Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 4572 | Register length = length_loc.AsRegister<Register>(); |
| 4573 | if (index_loc.IsConstant()) { |
| 4574 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); |
| 4575 | __ cmpl(length, Immediate(value)); |
| 4576 | } else { |
| 4577 | __ cmpl(length, index_loc.AsRegister<Register>()); |
| 4578 | } |
| 4579 | codegen_->AddSlowPath(slow_path); |
| 4580 | __ j(kBelowEqual, slow_path->GetEntryLabel()); |
Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 4581 | } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4582 | } |
| 4583 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4584 | void LocationsBuilderX86::VisitTemporary(HTemporary* temp) { |
| 4585 | temp->SetLocations(nullptr); |
| 4586 | } |
| 4587 | |
| 4588 | void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) { |
| 4589 | // Nothing to do, this is driven by the code generator. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4590 | UNUSED(temp); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4591 | } |
| 4592 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4593 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4594 | UNUSED(instruction); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4595 | LOG(FATAL) << "Unreachable"; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4596 | } |
| 4597 | |
| 4598 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4599 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); |
| 4600 | } |
| 4601 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4602 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
| 4603 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath); |
| 4604 | } |
| 4605 | |
| 4606 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4607 | HBasicBlock* block = instruction->GetBlock(); |
| 4608 | if (block->GetLoopInformation() != nullptr) { |
| 4609 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); |
| 4610 | // The back edge will generate the suspend check. |
| 4611 | return; |
| 4612 | } |
| 4613 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { |
| 4614 | // The goto will generate the suspend check. |
| 4615 | return; |
| 4616 | } |
| 4617 | GenerateSuspendCheck(instruction, nullptr); |
| 4618 | } |
| 4619 | |
| 4620 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, |
| 4621 | HBasicBlock* successor) { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4622 | SuspendCheckSlowPathX86* slow_path = |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4623 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); |
| 4624 | if (slow_path == nullptr) { |
| 4625 | slow_path = new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor); |
| 4626 | instruction->SetSlowPath(slow_path); |
| 4627 | codegen_->AddSlowPath(slow_path); |
| 4628 | if (successor != nullptr) { |
| 4629 | DCHECK(successor->IsLoopHeader()); |
| 4630 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(instruction); |
| 4631 | } |
| 4632 | } else { |
| 4633 | DCHECK_EQ(slow_path->GetSuccessor(), successor); |
| 4634 | } |
| 4635 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4636 | __ fs()->cmpw(Address::Absolute( |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4637 | Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0)); |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 4638 | if (successor == nullptr) { |
| 4639 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 4640 | __ Bind(slow_path->GetReturnLabel()); |
| 4641 | } else { |
| 4642 | __ j(kEqual, codegen_->GetLabelOf(successor)); |
| 4643 | __ jmp(slow_path->GetEntryLabel()); |
| 4644 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4645 | } |
| 4646 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4647 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { |
| 4648 | return codegen_->GetAssembler(); |
| 4649 | } |
| 4650 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4651 | void ParallelMoveResolverX86::MoveMemoryToMemory32(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4652 | ScratchRegisterScope ensure_scratch( |
| 4653 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4654 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4655 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4656 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4657 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | void ParallelMoveResolverX86::MoveMemoryToMemory64(int dst, int src) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4661 | ScratchRegisterScope ensure_scratch( |
| 4662 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4663 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4664 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4665 | __ movl(temp_reg, Address(ESP, src + stack_offset)); |
| 4666 | __ movl(Address(ESP, dst + stack_offset), temp_reg); |
| 4667 | __ movl(temp_reg, Address(ESP, src + stack_offset + kX86WordSize)); |
| 4668 | __ movl(Address(ESP, dst + stack_offset + kX86WordSize), temp_reg); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | void ParallelMoveResolverX86::EmitMove(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4672 | DCHECK_LT(index, moves_.size()); |
| 4673 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4674 | Location source = move->GetSource(); |
| 4675 | Location destination = move->GetDestination(); |
| 4676 | |
| 4677 | if (source.IsRegister()) { |
| 4678 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4679 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4680 | } else { |
| 4681 | DCHECK(destination.IsStackSlot()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4682 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4683 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4684 | } else if (source.IsFpuRegister()) { |
| 4685 | if (destination.IsFpuRegister()) { |
| 4686 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4687 | } else if (destination.IsStackSlot()) { |
| 4688 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4689 | } else { |
| 4690 | DCHECK(destination.IsDoubleStackSlot()); |
| 4691 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); |
| 4692 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4693 | } else if (source.IsStackSlot()) { |
| 4694 | if (destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4695 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4696 | } else if (destination.IsFpuRegister()) { |
| 4697 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4698 | } else { |
| 4699 | DCHECK(destination.IsStackSlot()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4700 | MoveMemoryToMemory32(destination.GetStackIndex(), source.GetStackIndex()); |
| 4701 | } |
| 4702 | } else if (source.IsDoubleStackSlot()) { |
| 4703 | if (destination.IsFpuRegister()) { |
| 4704 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); |
| 4705 | } else { |
| 4706 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4707 | MoveMemoryToMemory64(destination.GetStackIndex(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4708 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4709 | } else if (source.IsConstant()) { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4710 | HConstant* constant = source.GetConstant(); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 4711 | if (constant->IsIntConstant() || constant->IsNullConstant()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4712 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4713 | if (destination.IsRegister()) { |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4714 | if (value == 0) { |
| 4715 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4716 | } else { |
| 4717 | __ movl(destination.AsRegister<Register>(), Immediate(value)); |
| 4718 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4719 | } else { |
| 4720 | DCHECK(destination.IsStackSlot()) << destination; |
Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 4721 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4722 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4723 | } else if (constant->IsFloatConstant()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4724 | float fp_value = constant->AsFloatConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4725 | int32_t value = bit_cast<int32_t, float>(fp_value); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4726 | Immediate imm(value); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4727 | if (destination.IsFpuRegister()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4728 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4729 | if (value == 0) { |
| 4730 | // Easy handling of 0.0. |
| 4731 | __ xorps(dest, dest); |
| 4732 | } else { |
| 4733 | ScratchRegisterScope ensure_scratch( |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4734 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4735 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4736 | __ movl(temp, Immediate(value)); |
| 4737 | __ movd(dest, temp); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4738 | } |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4739 | } else { |
| 4740 | DCHECK(destination.IsStackSlot()) << destination; |
| 4741 | __ movl(Address(ESP, destination.GetStackIndex()), imm); |
| 4742 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4743 | } else if (constant->IsLongConstant()) { |
| 4744 | int64_t value = constant->AsLongConstant()->GetValue(); |
| 4745 | int32_t low_value = Low32Bits(value); |
| 4746 | int32_t high_value = High32Bits(value); |
| 4747 | Immediate low(low_value); |
| 4748 | Immediate high(high_value); |
| 4749 | if (destination.IsDoubleStackSlot()) { |
| 4750 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4751 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4752 | } else { |
| 4753 | __ movl(destination.AsRegisterPairLow<Register>(), low); |
| 4754 | __ movl(destination.AsRegisterPairHigh<Register>(), high); |
| 4755 | } |
| 4756 | } else { |
| 4757 | DCHECK(constant->IsDoubleConstant()); |
| 4758 | double dbl_value = constant->AsDoubleConstant()->GetValue(); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 4759 | int64_t value = bit_cast<int64_t, double>(dbl_value); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4760 | int32_t low_value = Low32Bits(value); |
| 4761 | int32_t high_value = High32Bits(value); |
| 4762 | Immediate low(low_value); |
| 4763 | Immediate high(high_value); |
| 4764 | if (destination.IsFpuRegister()) { |
| 4765 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); |
| 4766 | if (value == 0) { |
| 4767 | // Easy handling of 0.0. |
| 4768 | __ xorpd(dest, dest); |
| 4769 | } else { |
| 4770 | __ pushl(high); |
| 4771 | __ pushl(low); |
| 4772 | __ movsd(dest, Address(ESP, 0)); |
| 4773 | __ addl(ESP, Immediate(8)); |
| 4774 | } |
| 4775 | } else { |
| 4776 | DCHECK(destination.IsDoubleStackSlot()) << destination; |
| 4777 | __ movl(Address(ESP, destination.GetStackIndex()), low); |
| 4778 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); |
| 4779 | } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4780 | } |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4781 | } else { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 4782 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | |
Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 4786 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4787 | Register suggested_scratch = reg == EAX ? EBX : EAX; |
| 4788 | ScratchRegisterScope ensure_scratch( |
| 4789 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
| 4790 | |
| 4791 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4792 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); |
| 4793 | __ movl(Address(ESP, mem + stack_offset), reg); |
| 4794 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4795 | } |
| 4796 | |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4797 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4798 | ScratchRegisterScope ensure_scratch( |
| 4799 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
| 4800 | |
| 4801 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); |
| 4802 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; |
| 4803 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); |
| 4804 | __ movss(Address(ESP, mem + stack_offset), reg); |
| 4805 | __ movd(reg, temp_reg); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4806 | } |
| 4807 | |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4808 | void ParallelMoveResolverX86::Exchange(int mem1, int mem2) { |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4809 | ScratchRegisterScope ensure_scratch1( |
| 4810 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4811 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4812 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; |
| 4813 | ScratchRegisterScope ensure_scratch2( |
| 4814 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); |
Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 4815 | |
Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 4816 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; |
| 4817 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; |
| 4818 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); |
| 4819 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); |
| 4820 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); |
| 4821 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | void ParallelMoveResolverX86::EmitSwap(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 4825 | DCHECK_LT(index, moves_.size()); |
| 4826 | MoveOperands* move = moves_[index]; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4827 | Location source = move->GetSource(); |
| 4828 | Location destination = move->GetDestination(); |
| 4829 | |
| 4830 | if (source.IsRegister() && destination.IsRegister()) { |
Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 4831 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. |
| 4832 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4833 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
| 4834 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); |
| 4835 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4836 | } else if (source.IsRegister() && destination.IsStackSlot()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4837 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4838 | } else if (source.IsStackSlot() && destination.IsRegister()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4839 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4840 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { |
| 4841 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4842 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { |
| 4843 | // Use XOR Swap algorithm to avoid a temporary. |
| 4844 | DCHECK_NE(source.reg(), destination.reg()); |
| 4845 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4846 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); |
| 4847 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); |
| 4848 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { |
| 4849 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); |
| 4850 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { |
| 4851 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4852 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { |
| 4853 | // Take advantage of the 16 bytes in the XMM register. |
| 4854 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); |
| 4855 | Address stack(ESP, destination.GetStackIndex()); |
| 4856 | // Load the double into the high doubleword. |
| 4857 | __ movhpd(reg, stack); |
| 4858 | |
| 4859 | // Store the low double into the destination. |
| 4860 | __ movsd(stack, reg); |
| 4861 | |
| 4862 | // Move the high double to the low double. |
| 4863 | __ psrldq(reg, Immediate(8)); |
| 4864 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { |
| 4865 | // Take advantage of the 16 bytes in the XMM register. |
| 4866 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); |
| 4867 | Address stack(ESP, source.GetStackIndex()); |
| 4868 | // Load the double into the high doubleword. |
| 4869 | __ movhpd(reg, stack); |
| 4870 | |
| 4871 | // Store the low double into the destination. |
| 4872 | __ movsd(stack, reg); |
| 4873 | |
| 4874 | // Move the high double to the low double. |
| 4875 | __ psrldq(reg, Immediate(8)); |
| 4876 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { |
| 4877 | Exchange(destination.GetStackIndex(), source.GetStackIndex()); |
| 4878 | Exchange(destination.GetHighStackIndex(kX86WordSize), source.GetHighStackIndex(kX86WordSize)); |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4879 | } else { |
Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 4880 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; |
Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4881 | } |
| 4882 | } |
| 4883 | |
| 4884 | void ParallelMoveResolverX86::SpillScratch(int reg) { |
| 4885 | __ pushl(static_cast<Register>(reg)); |
| 4886 | } |
| 4887 | |
| 4888 | void ParallelMoveResolverX86::RestoreScratch(int reg) { |
| 4889 | __ popl(static_cast<Register>(reg)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4890 | } |
| 4891 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4892 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4893 | LocationSummary::CallKind call_kind = cls->CanCallRuntime() |
| 4894 | ? LocationSummary::kCallOnSlowPath |
| 4895 | : LocationSummary::kNoCall; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4896 | LocationSummary* locations = |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4897 | new (GetGraph()->GetArena()) LocationSummary(cls, call_kind); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4898 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4899 | locations->SetOut(Location::RequiresRegister()); |
| 4900 | } |
| 4901 | |
| 4902 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4903 | LocationSummary* locations = cls->GetLocations(); |
| 4904 | Register out = locations->Out().AsRegister<Register>(); |
| 4905 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4906 | if (cls->IsReferrersClass()) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4907 | DCHECK(!cls->CanCallRuntime()); |
| 4908 | DCHECK(!cls->MustGenerateClinitCheck()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4909 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4910 | } else { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4911 | DCHECK(cls->CanCallRuntime()); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4912 | __ movl(out, Address( |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4913 | current_method, ArtMethod::DexCacheResolvedTypesOffset(kX86PointerSize).Int32Value())); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4914 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4915 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4916 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4917 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4918 | cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck()); |
| 4919 | codegen_->AddSlowPath(slow_path); |
| 4920 | __ testl(out, out); |
| 4921 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4922 | if (cls->MustGenerateClinitCheck()) { |
| 4923 | GenerateClassInitializationCheck(slow_path, out); |
| 4924 | } else { |
| 4925 | __ Bind(slow_path->GetExitLabel()); |
| 4926 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4927 | } |
| 4928 | } |
| 4929 | |
| 4930 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { |
| 4931 | LocationSummary* locations = |
| 4932 | new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath); |
| 4933 | locations->SetInAt(0, Location::RequiresRegister()); |
| 4934 | if (check->HasUses()) { |
| 4935 | locations->SetOut(Location::SameAsFirstInput()); |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4940 | // We assume the class to not be null. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4941 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86( |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4942 | check->GetLoadClass(), check, check->GetDexPc(), true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4943 | codegen_->AddSlowPath(slow_path); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 4944 | GenerateClassInitializationCheck(slow_path, |
| 4945 | check->GetLocations()->InAt(0).AsRegister<Register>()); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4946 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4947 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4948 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4949 | SlowPathCode* slow_path, Register class_reg) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4950 | __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()), |
| 4951 | Immediate(mirror::Class::kStatusInitialized)); |
| 4952 | __ j(kLess, slow_path->GetEntryLabel()); |
| 4953 | __ Bind(slow_path->GetExitLabel()); |
| 4954 | // No need for memory fence, thanks to the X86 memory model. |
| 4955 | } |
| 4956 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4957 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { |
| 4958 | LocationSummary* locations = |
| 4959 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4960 | locations->SetInAt(0, Location::RequiresRegister()); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4961 | locations->SetOut(Location::RequiresRegister()); |
| 4962 | } |
| 4963 | |
| 4964 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) { |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 4965 | SlowPathCode* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4966 | codegen_->AddSlowPath(slow_path); |
| 4967 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4968 | LocationSummary* locations = load->GetLocations(); |
| 4969 | Register out = locations->Out().AsRegister<Register>(); |
| 4970 | Register current_method = locations->InAt(0).AsRegister<Register>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 4971 | __ movl(out, Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value())); |
Mathieu Chartier | eace458 | 2014-11-24 18:29:54 -0800 | [diff] [blame] | 4972 | __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value())); |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4973 | __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex()))); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 4974 | // TODO: We will need a read barrier here. |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4975 | __ testl(out, out); |
| 4976 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 4977 | __ Bind(slow_path->GetExitLabel()); |
| 4978 | } |
| 4979 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4980 | static Address GetExceptionTlsAddress() { |
| 4981 | return Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value()); |
| 4982 | } |
| 4983 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4984 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { |
| 4985 | LocationSummary* locations = |
| 4986 | new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall); |
| 4987 | locations->SetOut(Location::RequiresRegister()); |
| 4988 | } |
| 4989 | |
| 4990 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4991 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); |
| 4992 | } |
| 4993 | |
| 4994 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { |
| 4995 | new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall); |
| 4996 | } |
| 4997 | |
| 4998 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { |
| 4999 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5000 | } |
| 5001 | |
| 5002 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { |
| 5003 | LocationSummary* locations = |
| 5004 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5005 | InvokeRuntimeCallingConvention calling_convention; |
| 5006 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5007 | } |
| 5008 | |
| 5009 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5010 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pDeliverException), |
| 5011 | instruction, |
| 5012 | instruction->GetDexPc(), |
| 5013 | nullptr); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5014 | } |
| 5015 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5016 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5017 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5018 | switch (instruction->GetTypeCheckKind()) { |
| 5019 | case TypeCheckKind::kExactCheck: |
| 5020 | case TypeCheckKind::kAbstractClassCheck: |
| 5021 | case TypeCheckKind::kClassHierarchyCheck: |
| 5022 | case TypeCheckKind::kArrayObjectCheck: |
| 5023 | call_kind = LocationSummary::kNoCall; |
| 5024 | break; |
| 5025 | case TypeCheckKind::kInterfaceCheck: |
| 5026 | call_kind = LocationSummary::kCall; |
| 5027 | break; |
| 5028 | case TypeCheckKind::kArrayCheck: |
| 5029 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5030 | break; |
| 5031 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5032 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5033 | if (call_kind != LocationSummary::kCall) { |
| 5034 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5035 | locations->SetInAt(1, Location::Any()); |
| 5036 | // Note that TypeCheckSlowPathX86 uses this register too. |
| 5037 | locations->SetOut(Location::RequiresRegister()); |
| 5038 | } else { |
| 5039 | InvokeRuntimeCallingConvention calling_convention; |
| 5040 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5041 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5042 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 5043 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5044 | } |
| 5045 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5046 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5047 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5048 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5049 | Location cls = locations->InAt(1); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5050 | Register out = locations->Out().AsRegister<Register>(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5051 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5052 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5053 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5054 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5055 | SlowPathCode* slow_path = nullptr; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5056 | NearLabel done, zero; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5057 | |
| 5058 | // Return 0 if `obj` is null. |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5059 | // Avoid null check if we know obj is not null. |
| 5060 | if (instruction->MustDoNullCheck()) { |
| 5061 | __ testl(obj, obj); |
| 5062 | __ j(kEqual, &zero); |
| 5063 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5064 | |
| 5065 | // In case of an interface check, we put the object class into the object register. |
| 5066 | // This is safe, as the register is caller-save, and the object must be in another |
| 5067 | // register if it survives the runtime call. |
| 5068 | Register target = (instruction->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) |
| 5069 | ? obj |
| 5070 | : out; |
| 5071 | __ movl(target, Address(obj, class_offset)); |
| 5072 | __ MaybeUnpoisonHeapReference(target); |
| 5073 | |
| 5074 | switch (instruction->GetTypeCheckKind()) { |
| 5075 | case TypeCheckKind::kExactCheck: { |
| 5076 | if (cls.IsRegister()) { |
| 5077 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5078 | } else { |
| 5079 | DCHECK(cls.IsStackSlot()) << cls; |
| 5080 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5081 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5082 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5083 | // Classes must be equal for the instanceof to succeed. |
| 5084 | __ j(kNotEqual, &zero); |
| 5085 | __ movl(out, Immediate(1)); |
| 5086 | __ jmp(&done); |
| 5087 | break; |
| 5088 | } |
| 5089 | case TypeCheckKind::kAbstractClassCheck: { |
| 5090 | // If the class is abstract, we eagerly fetch the super class of the |
| 5091 | // object to avoid doing a comparison we know will fail. |
| 5092 | NearLabel loop; |
| 5093 | __ Bind(&loop); |
| 5094 | __ movl(out, Address(out, super_offset)); |
| 5095 | __ MaybeUnpoisonHeapReference(out); |
| 5096 | __ testl(out, out); |
| 5097 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5098 | __ j(kEqual, &done); |
| 5099 | if (cls.IsRegister()) { |
| 5100 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5101 | } else { |
| 5102 | DCHECK(cls.IsStackSlot()) << cls; |
| 5103 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5104 | } |
| 5105 | __ j(kNotEqual, &loop); |
| 5106 | __ movl(out, Immediate(1)); |
| 5107 | if (zero.IsLinked()) { |
| 5108 | __ jmp(&done); |
| 5109 | } |
| 5110 | break; |
| 5111 | } |
| 5112 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5113 | // Walk over the class hierarchy to find a match. |
| 5114 | NearLabel loop, success; |
| 5115 | __ Bind(&loop); |
| 5116 | if (cls.IsRegister()) { |
| 5117 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5118 | } else { |
| 5119 | DCHECK(cls.IsStackSlot()) << cls; |
| 5120 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5121 | } |
| 5122 | __ j(kEqual, &success); |
| 5123 | __ movl(out, Address(out, super_offset)); |
| 5124 | __ MaybeUnpoisonHeapReference(out); |
| 5125 | __ testl(out, out); |
| 5126 | __ j(kNotEqual, &loop); |
| 5127 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5128 | __ jmp(&done); |
| 5129 | __ Bind(&success); |
| 5130 | __ movl(out, Immediate(1)); |
| 5131 | if (zero.IsLinked()) { |
| 5132 | __ jmp(&done); |
| 5133 | } |
| 5134 | break; |
| 5135 | } |
| 5136 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5137 | // Do an exact check. |
| 5138 | NearLabel exact_check; |
| 5139 | if (cls.IsRegister()) { |
| 5140 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5141 | } else { |
| 5142 | DCHECK(cls.IsStackSlot()) << cls; |
| 5143 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5144 | } |
| 5145 | __ j(kEqual, &exact_check); |
| 5146 | // 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] | 5147 | __ movl(out, Address(out, component_offset)); |
| 5148 | __ MaybeUnpoisonHeapReference(out); |
| 5149 | __ testl(out, out); |
| 5150 | // If `out` is null, we use it for the result, and jump to `done`. |
| 5151 | __ j(kEqual, &done); |
| 5152 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5153 | __ j(kNotEqual, &zero); |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5154 | __ Bind(&exact_check); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5155 | __ movl(out, Immediate(1)); |
| 5156 | __ jmp(&done); |
| 5157 | break; |
| 5158 | } |
| 5159 | case TypeCheckKind::kArrayCheck: { |
| 5160 | if (cls.IsRegister()) { |
| 5161 | __ cmpl(out, cls.AsRegister<Register>()); |
| 5162 | } else { |
| 5163 | DCHECK(cls.IsStackSlot()) << cls; |
| 5164 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); |
| 5165 | } |
| 5166 | DCHECK(locations->OnlyCallsOnSlowPath()); |
| 5167 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 5168 | instruction, /* is_fatal */ false); |
| 5169 | codegen_->AddSlowPath(slow_path); |
| 5170 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5171 | __ movl(out, Immediate(1)); |
| 5172 | if (zero.IsLinked()) { |
| 5173 | __ jmp(&done); |
| 5174 | } |
| 5175 | break; |
| 5176 | } |
| 5177 | |
| 5178 | case TypeCheckKind::kInterfaceCheck: |
| 5179 | default: { |
| 5180 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), |
| 5181 | instruction, |
| 5182 | instruction->GetDexPc(), |
| 5183 | nullptr); |
| 5184 | if (zero.IsLinked()) { |
| 5185 | __ jmp(&done); |
| 5186 | } |
| 5187 | break; |
| 5188 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5191 | if (zero.IsLinked()) { |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5192 | __ Bind(&zero); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5193 | __ xorl(out, out); |
| 5194 | } |
| 5195 | |
| 5196 | if (done.IsLinked()) { |
| 5197 | __ Bind(&done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5198 | } |
| 5199 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5200 | if (slow_path != nullptr) { |
| 5201 | __ Bind(slow_path->GetExitLabel()); |
| 5202 | } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5205 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5206 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; |
| 5207 | bool throws_into_catch = instruction->CanThrowIntoCatchBlock(); |
| 5208 | |
| 5209 | switch (instruction->GetTypeCheckKind()) { |
| 5210 | case TypeCheckKind::kExactCheck: |
| 5211 | case TypeCheckKind::kAbstractClassCheck: |
| 5212 | case TypeCheckKind::kClassHierarchyCheck: |
| 5213 | case TypeCheckKind::kArrayObjectCheck: |
| 5214 | call_kind = throws_into_catch |
| 5215 | ? LocationSummary::kCallOnSlowPath |
| 5216 | : LocationSummary::kNoCall; |
| 5217 | break; |
| 5218 | case TypeCheckKind::kInterfaceCheck: |
| 5219 | call_kind = LocationSummary::kCall; |
| 5220 | break; |
| 5221 | case TypeCheckKind::kArrayCheck: |
| 5222 | call_kind = LocationSummary::kCallOnSlowPath; |
| 5223 | break; |
| 5224 | } |
| 5225 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5226 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary( |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5227 | instruction, call_kind); |
| 5228 | if (call_kind != LocationSummary::kCall) { |
| 5229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5230 | locations->SetInAt(1, Location::Any()); |
| 5231 | // Note that TypeCheckSlowPathX86 uses this register too. |
| 5232 | locations->AddTemp(Location::RequiresRegister()); |
| 5233 | } else { |
| 5234 | InvokeRuntimeCallingConvention calling_convention; |
| 5235 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5236 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 5237 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5238 | } |
| 5239 | |
| 5240 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { |
| 5241 | LocationSummary* locations = instruction->GetLocations(); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5242 | Register obj = locations->InAt(0).AsRegister<Register>(); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5243 | Location cls = locations->InAt(1); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5244 | Register temp = locations->WillCall() |
| 5245 | ? kNoRegister |
| 5246 | : locations->GetTemp(0).AsRegister<Register>(); |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 5247 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5248 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 5249 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 5250 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 5251 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 5252 | SlowPathCode* slow_path = nullptr; |
| 5253 | |
| 5254 | if (!locations->WillCall()) { |
| 5255 | slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86( |
| 5256 | instruction, !locations->CanCall()); |
| 5257 | codegen_->AddSlowPath(slow_path); |
| 5258 | } |
| 5259 | |
| 5260 | NearLabel done, abstract_entry; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5261 | // Avoid null check if we know obj is not null. |
| 5262 | if (instruction->MustDoNullCheck()) { |
| 5263 | __ testl(obj, obj); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5264 | __ j(kEqual, &done); |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5265 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5266 | |
| 5267 | if (locations->WillCall()) { |
| 5268 | __ movl(obj, Address(obj, class_offset)); |
| 5269 | __ MaybeUnpoisonHeapReference(obj); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5270 | } else { |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5271 | __ movl(temp, Address(obj, class_offset)); |
| 5272 | __ MaybeUnpoisonHeapReference(temp); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5273 | } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5274 | |
| 5275 | switch (instruction->GetTypeCheckKind()) { |
| 5276 | case TypeCheckKind::kExactCheck: |
| 5277 | case TypeCheckKind::kArrayCheck: { |
| 5278 | if (cls.IsRegister()) { |
| 5279 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5280 | } else { |
| 5281 | DCHECK(cls.IsStackSlot()) << cls; |
| 5282 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5283 | } |
| 5284 | // Jump to slow path for throwing the exception or doing a |
| 5285 | // more involved array check. |
| 5286 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5287 | break; |
| 5288 | } |
| 5289 | case TypeCheckKind::kAbstractClassCheck: { |
| 5290 | // If the class is abstract, we eagerly fetch the super class of the |
| 5291 | // object to avoid doing a comparison we know will fail. |
| 5292 | NearLabel loop, success; |
| 5293 | __ Bind(&loop); |
| 5294 | __ movl(temp, Address(temp, super_offset)); |
| 5295 | __ MaybeUnpoisonHeapReference(temp); |
| 5296 | __ testl(temp, temp); |
| 5297 | // Jump to the slow path to throw the exception. |
| 5298 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5299 | if (cls.IsRegister()) { |
| 5300 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5301 | } else { |
| 5302 | DCHECK(cls.IsStackSlot()) << cls; |
| 5303 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5304 | } |
| 5305 | __ j(kNotEqual, &loop); |
| 5306 | break; |
| 5307 | } |
| 5308 | case TypeCheckKind::kClassHierarchyCheck: { |
| 5309 | // Walk over the class hierarchy to find a match. |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5310 | NearLabel loop; |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5311 | __ Bind(&loop); |
| 5312 | if (cls.IsRegister()) { |
| 5313 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5314 | } else { |
| 5315 | DCHECK(cls.IsStackSlot()) << cls; |
| 5316 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5317 | } |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5318 | __ j(kEqual, &done); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5319 | __ movl(temp, Address(temp, super_offset)); |
| 5320 | __ MaybeUnpoisonHeapReference(temp); |
| 5321 | __ testl(temp, temp); |
| 5322 | __ j(kNotEqual, &loop); |
| 5323 | // Jump to the slow path to throw the exception. |
| 5324 | __ jmp(slow_path->GetEntryLabel()); |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5325 | break; |
| 5326 | } |
| 5327 | case TypeCheckKind::kArrayObjectCheck: { |
Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 5328 | // Do an exact check. |
| 5329 | if (cls.IsRegister()) { |
| 5330 | __ cmpl(temp, cls.AsRegister<Register>()); |
| 5331 | } else { |
| 5332 | DCHECK(cls.IsStackSlot()) << cls; |
| 5333 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); |
| 5334 | } |
| 5335 | __ j(kEqual, &done); |
| 5336 | // 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] | 5337 | __ movl(temp, Address(temp, component_offset)); |
| 5338 | __ MaybeUnpoisonHeapReference(temp); |
| 5339 | __ testl(temp, temp); |
| 5340 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 5341 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 5342 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
| 5343 | break; |
| 5344 | } |
| 5345 | case TypeCheckKind::kInterfaceCheck: |
| 5346 | default: |
| 5347 | codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), |
| 5348 | instruction, |
| 5349 | instruction->GetDexPc(), |
| 5350 | nullptr); |
| 5351 | break; |
| 5352 | } |
| 5353 | __ Bind(&done); |
| 5354 | |
| 5355 | if (slow_path != nullptr) { |
| 5356 | __ Bind(slow_path->GetExitLabel()); |
| 5357 | } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5358 | } |
| 5359 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5360 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
| 5361 | LocationSummary* locations = |
| 5362 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall); |
| 5363 | InvokeRuntimeCallingConvention calling_convention; |
| 5364 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 5365 | } |
| 5366 | |
| 5367 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { |
Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 5368 | codegen_->InvokeRuntime(instruction->IsEnter() ? QUICK_ENTRY_POINT(pLockObject) |
| 5369 | : QUICK_ENTRY_POINT(pUnlockObject), |
| 5370 | instruction, |
| 5371 | instruction->GetDexPc(), |
| 5372 | nullptr); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5373 | } |
| 5374 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5375 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } |
| 5376 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } |
| 5377 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } |
| 5378 | |
| 5379 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5380 | LocationSummary* locations = |
| 5381 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5382 | DCHECK(instruction->GetResultType() == Primitive::kPrimInt |
| 5383 | || instruction->GetResultType() == Primitive::kPrimLong); |
| 5384 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5385 | locations->SetInAt(1, Location::Any()); |
| 5386 | locations->SetOut(Location::SameAsFirstInput()); |
| 5387 | } |
| 5388 | |
| 5389 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { |
| 5390 | HandleBitwiseOperation(instruction); |
| 5391 | } |
| 5392 | |
| 5393 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { |
| 5394 | HandleBitwiseOperation(instruction); |
| 5395 | } |
| 5396 | |
| 5397 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { |
| 5398 | HandleBitwiseOperation(instruction); |
| 5399 | } |
| 5400 | |
| 5401 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { |
| 5402 | LocationSummary* locations = instruction->GetLocations(); |
| 5403 | Location first = locations->InAt(0); |
| 5404 | Location second = locations->InAt(1); |
| 5405 | DCHECK(first.Equals(locations->Out())); |
| 5406 | |
| 5407 | if (instruction->GetResultType() == Primitive::kPrimInt) { |
| 5408 | if (second.IsRegister()) { |
| 5409 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5410 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5411 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5412 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5413 | } else { |
| 5414 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5415 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5416 | } |
| 5417 | } else if (second.IsConstant()) { |
| 5418 | if (instruction->IsAnd()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5419 | __ andl(first.AsRegister<Register>(), |
| 5420 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5421 | } else if (instruction->IsOr()) { |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5422 | __ orl(first.AsRegister<Register>(), |
| 5423 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5424 | } else { |
| 5425 | DCHECK(instruction->IsXor()); |
Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 5426 | __ xorl(first.AsRegister<Register>(), |
| 5427 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5428 | } |
| 5429 | } else { |
| 5430 | if (instruction->IsAnd()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5431 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5432 | } else if (instruction->IsOr()) { |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5433 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5434 | } else { |
| 5435 | DCHECK(instruction->IsXor()); |
Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 5436 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5437 | } |
| 5438 | } |
| 5439 | } else { |
| 5440 | DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong); |
| 5441 | if (second.IsRegisterPair()) { |
| 5442 | if (instruction->IsAnd()) { |
| 5443 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5444 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5445 | } else if (instruction->IsOr()) { |
| 5446 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5447 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5448 | } else { |
| 5449 | DCHECK(instruction->IsXor()); |
| 5450 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); |
| 5451 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); |
| 5452 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5453 | } else if (second.IsDoubleStackSlot()) { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5454 | if (instruction->IsAnd()) { |
| 5455 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5456 | __ andl(first.AsRegisterPairHigh<Register>(), |
| 5457 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5458 | } else if (instruction->IsOr()) { |
| 5459 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5460 | __ orl(first.AsRegisterPairHigh<Register>(), |
| 5461 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5462 | } else { |
| 5463 | DCHECK(instruction->IsXor()); |
| 5464 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); |
| 5465 | __ xorl(first.AsRegisterPairHigh<Register>(), |
| 5466 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); |
| 5467 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5468 | } else { |
| 5469 | DCHECK(second.IsConstant()) << second; |
| 5470 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5471 | int32_t low_value = Low32Bits(value); |
| 5472 | int32_t high_value = High32Bits(value); |
| 5473 | Immediate low(low_value); |
| 5474 | Immediate high(high_value); |
| 5475 | Register first_low = first.AsRegisterPairLow<Register>(); |
| 5476 | Register first_high = first.AsRegisterPairHigh<Register>(); |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5477 | if (instruction->IsAnd()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5478 | if (low_value == 0) { |
| 5479 | __ xorl(first_low, first_low); |
| 5480 | } else if (low_value != -1) { |
| 5481 | __ andl(first_low, low); |
| 5482 | } |
| 5483 | if (high_value == 0) { |
| 5484 | __ xorl(first_high, first_high); |
| 5485 | } else if (high_value != -1) { |
| 5486 | __ andl(first_high, high); |
| 5487 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5488 | } else if (instruction->IsOr()) { |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5489 | if (low_value != 0) { |
| 5490 | __ orl(first_low, low); |
| 5491 | } |
| 5492 | if (high_value != 0) { |
| 5493 | __ orl(first_high, high); |
| 5494 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5495 | } else { |
| 5496 | DCHECK(instruction->IsXor()); |
Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 5497 | if (low_value != 0) { |
| 5498 | __ xorl(first_low, low); |
| 5499 | } |
| 5500 | if (high_value != 0) { |
| 5501 | __ xorl(first_high, high); |
| 5502 | } |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5503 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5504 | } |
| 5505 | } |
| 5506 | } |
| 5507 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5508 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction) { |
| 5509 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5510 | UNUSED(instruction); |
| 5511 | LOG(FATAL) << "Unreachable"; |
| 5512 | } |
| 5513 | |
| 5514 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction) { |
| 5515 | // Nothing to do, this should be removed during prepare for register allocator. |
| 5516 | UNUSED(instruction); |
| 5517 | LOG(FATAL) << "Unreachable"; |
| 5518 | } |
| 5519 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5520 | void LocationsBuilderX86::VisitFakeString(HFakeString* instruction) { |
| 5521 | DCHECK(codegen_->IsBaseline()); |
| 5522 | LocationSummary* locations = |
| 5523 | new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall); |
| 5524 | locations->SetOut(Location::ConstantLocation(GetGraph()->GetNullConstant())); |
| 5525 | } |
| 5526 | |
| 5527 | void InstructionCodeGeneratorX86::VisitFakeString(HFakeString* instruction ATTRIBUTE_UNUSED) { |
| 5528 | DCHECK(codegen_->IsBaseline()); |
| 5529 | // Will be generated at use site. |
| 5530 | } |
| 5531 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 5532 | // Simple implementation of packed switch - generate cascaded compare/jumps. |
| 5533 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5534 | LocationSummary* locations = |
| 5535 | new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall); |
| 5536 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5537 | } |
| 5538 | |
| 5539 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { |
| 5540 | int32_t lower_bound = switch_instr->GetStartValue(); |
| 5541 | int32_t num_entries = switch_instr->GetNumEntries(); |
| 5542 | LocationSummary* locations = switch_instr->GetLocations(); |
| 5543 | Register value_reg = locations->InAt(0).AsRegister<Register>(); |
| 5544 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); |
| 5545 | |
| 5546 | // Create a series of compare/jumps. |
| 5547 | const ArenaVector<HBasicBlock*>& successors = switch_instr->GetBlock()->GetSuccessors(); |
| 5548 | for (int i = 0; i < num_entries; i++) { |
| 5549 | int32_t case_value = lower_bound + i; |
| 5550 | if (case_value == 0) { |
| 5551 | __ testl(value_reg, value_reg); |
| 5552 | } else { |
| 5553 | __ cmpl(value_reg, Immediate(case_value)); |
| 5554 | } |
| 5555 | __ j(kEqual, codegen_->GetLabelOf(successors.at(i))); |
| 5556 | } |
| 5557 | |
| 5558 | // And the default for any other value. |
| 5559 | if (!codegen_->GoesToNextBlock(switch_instr->GetBlock(), default_block)) { |
| 5560 | __ jmp(codegen_->GetLabelOf(default_block)); |
| 5561 | } |
| 5562 | } |
| 5563 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5564 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( |
| 5565 | HX86ComputeBaseMethodAddress* insn) { |
| 5566 | LocationSummary* locations = |
| 5567 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5568 | locations->SetOut(Location::RequiresRegister()); |
| 5569 | } |
| 5570 | |
| 5571 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( |
| 5572 | HX86ComputeBaseMethodAddress* insn) { |
| 5573 | LocationSummary* locations = insn->GetLocations(); |
| 5574 | Register reg = locations->Out().AsRegister<Register>(); |
| 5575 | |
| 5576 | // Generate call to next instruction. |
| 5577 | Label next_instruction; |
| 5578 | __ call(&next_instruction); |
| 5579 | __ Bind(&next_instruction); |
| 5580 | |
| 5581 | // Remember this offset for later use with constant area. |
| 5582 | codegen_->SetMethodAddressOffset(GetAssembler()->CodeSize()); |
| 5583 | |
| 5584 | // Grab the return address off the stack. |
| 5585 | __ popl(reg); |
| 5586 | } |
| 5587 | |
| 5588 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( |
| 5589 | HX86LoadFromConstantTable* insn) { |
| 5590 | LocationSummary* locations = |
| 5591 | new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall); |
| 5592 | |
| 5593 | locations->SetInAt(0, Location::RequiresRegister()); |
| 5594 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); |
| 5595 | |
| 5596 | // If we don't need to be materialized, we only need the inputs to be set. |
| 5597 | if (!insn->NeedsMaterialization()) { |
| 5598 | return; |
| 5599 | } |
| 5600 | |
| 5601 | switch (insn->GetType()) { |
| 5602 | case Primitive::kPrimFloat: |
| 5603 | case Primitive::kPrimDouble: |
| 5604 | locations->SetOut(Location::RequiresFpuRegister()); |
| 5605 | break; |
| 5606 | |
| 5607 | case Primitive::kPrimInt: |
| 5608 | locations->SetOut(Location::RequiresRegister()); |
| 5609 | break; |
| 5610 | |
| 5611 | default: |
| 5612 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { |
| 5617 | if (!insn->NeedsMaterialization()) { |
| 5618 | return; |
| 5619 | } |
| 5620 | |
| 5621 | LocationSummary* locations = insn->GetLocations(); |
| 5622 | Location out = locations->Out(); |
| 5623 | Register const_area = locations->InAt(0).AsRegister<Register>(); |
| 5624 | HConstant *value = insn->GetConstant(); |
| 5625 | |
| 5626 | switch (insn->GetType()) { |
| 5627 | case Primitive::kPrimFloat: |
| 5628 | __ movss(out.AsFpuRegister<XmmRegister>(), |
| 5629 | codegen_->LiteralFloatAddress(value->AsFloatConstant()->GetValue(), const_area)); |
| 5630 | break; |
| 5631 | |
| 5632 | case Primitive::kPrimDouble: |
| 5633 | __ movsd(out.AsFpuRegister<XmmRegister>(), |
| 5634 | codegen_->LiteralDoubleAddress(value->AsDoubleConstant()->GetValue(), const_area)); |
| 5635 | break; |
| 5636 | |
| 5637 | case Primitive::kPrimInt: |
| 5638 | __ movl(out.AsRegister<Register>(), |
| 5639 | codegen_->LiteralInt32Address(value->AsIntConstant()->GetValue(), const_area)); |
| 5640 | break; |
| 5641 | |
| 5642 | default: |
| 5643 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); |
| 5644 | } |
| 5645 | } |
| 5646 | |
| 5647 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { |
| 5648 | // Generate the constant area if needed. |
| 5649 | X86Assembler* assembler = GetAssembler(); |
| 5650 | if (!assembler->IsConstantAreaEmpty()) { |
| 5651 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 |
| 5652 | // byte values. |
| 5653 | assembler->Align(4, 0); |
| 5654 | constant_area_start_ = assembler->CodeSize(); |
| 5655 | assembler->AddConstantArea(); |
| 5656 | } |
| 5657 | |
| 5658 | // And finish up. |
| 5659 | CodeGenerator::Finalize(allocator); |
| 5660 | } |
| 5661 | |
| 5662 | /** |
| 5663 | * Class to handle late fixup of offsets into constant area. |
| 5664 | */ |
| 5665 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocMisc> { |
| 5666 | public: |
| 5667 | RIPFixup(const CodeGeneratorX86& codegen, int offset) |
| 5668 | : codegen_(codegen), offset_into_constant_area_(offset) {} |
| 5669 | |
| 5670 | private: |
| 5671 | void Process(const MemoryRegion& region, int pos) OVERRIDE { |
| 5672 | // Patch the correct offset for the instruction. The place to patch is the |
| 5673 | // last 4 bytes of the instruction. |
| 5674 | // The value to patch is the distance from the offset in the constant area |
| 5675 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. |
| 5676 | int32_t constant_offset = codegen_.ConstantAreaStart() + offset_into_constant_area_; |
| 5677 | int32_t relative_position = constant_offset - codegen_.GetMethodAddressOffset();; |
| 5678 | |
| 5679 | // Patch in the right value. |
| 5680 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); |
| 5681 | } |
| 5682 | |
| 5683 | const CodeGeneratorX86& codegen_; |
| 5684 | |
| 5685 | // Location in constant area that the fixup refers to. |
| 5686 | int offset_into_constant_area_; |
| 5687 | }; |
| 5688 | |
| 5689 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, Register reg) { |
| 5690 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddDouble(v)); |
| 5691 | return Address(reg, kDummy32BitOffset, fixup); |
| 5692 | } |
| 5693 | |
| 5694 | Address CodeGeneratorX86::LiteralFloatAddress(float v, Register reg) { |
| 5695 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddFloat(v)); |
| 5696 | return Address(reg, kDummy32BitOffset, fixup); |
| 5697 | } |
| 5698 | |
| 5699 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, Register reg) { |
| 5700 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt32(v)); |
| 5701 | return Address(reg, kDummy32BitOffset, fixup); |
| 5702 | } |
| 5703 | |
| 5704 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, Register reg) { |
| 5705 | AssemblerFixup* fixup = new (GetGraph()->GetArena()) RIPFixup(*this, __ AddInt64(v)); |
| 5706 | return Address(reg, kDummy32BitOffset, fixup); |
| 5707 | } |
| 5708 | |
| 5709 | /** |
| 5710 | * Finds instructions that need the constant area base as an input. |
| 5711 | */ |
| 5712 | class ConstantHandlerVisitor : public HGraphVisitor { |
| 5713 | public: |
| 5714 | explicit ConstantHandlerVisitor(HGraph* graph) : HGraphVisitor(graph), base_(nullptr) {} |
| 5715 | |
| 5716 | private: |
| 5717 | void VisitAdd(HAdd* add) OVERRIDE { |
| 5718 | BinaryFP(add); |
| 5719 | } |
| 5720 | |
| 5721 | void VisitSub(HSub* sub) OVERRIDE { |
| 5722 | BinaryFP(sub); |
| 5723 | } |
| 5724 | |
| 5725 | void VisitMul(HMul* mul) OVERRIDE { |
| 5726 | BinaryFP(mul); |
| 5727 | } |
| 5728 | |
| 5729 | void VisitDiv(HDiv* div) OVERRIDE { |
| 5730 | BinaryFP(div); |
| 5731 | } |
| 5732 | |
| 5733 | void VisitReturn(HReturn* ret) OVERRIDE { |
| 5734 | HConstant* value = ret->InputAt(0)->AsConstant(); |
| 5735 | if ((value != nullptr && Primitive::IsFloatingPointType(value->GetType()))) { |
| 5736 | ReplaceInput(ret, value, 0, true); |
| 5737 | } |
| 5738 | } |
| 5739 | |
| 5740 | void VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) OVERRIDE { |
| 5741 | HandleInvoke(invoke); |
| 5742 | } |
| 5743 | |
| 5744 | void VisitInvokeVirtual(HInvokeVirtual* invoke) OVERRIDE { |
| 5745 | HandleInvoke(invoke); |
| 5746 | } |
| 5747 | |
| 5748 | void VisitInvokeInterface(HInvokeInterface* invoke) OVERRIDE { |
| 5749 | HandleInvoke(invoke); |
| 5750 | } |
| 5751 | |
| 5752 | void BinaryFP(HBinaryOperation* bin) { |
| 5753 | HConstant* rhs = bin->InputAt(1)->AsConstant(); |
| 5754 | if (rhs != nullptr && Primitive::IsFloatingPointType(bin->GetResultType())) { |
| 5755 | ReplaceInput(bin, rhs, 1, false); |
| 5756 | } |
| 5757 | } |
| 5758 | |
| 5759 | void InitializeConstantAreaPointer(HInstruction* user) { |
| 5760 | // Ensure we only initialize the pointer once. |
| 5761 | if (base_ != nullptr) { |
| 5762 | return; |
| 5763 | } |
| 5764 | |
| 5765 | HGraph* graph = GetGraph(); |
| 5766 | HBasicBlock* entry = graph->GetEntryBlock(); |
| 5767 | base_ = new (graph->GetArena()) HX86ComputeBaseMethodAddress(); |
| 5768 | HInstruction* insert_pos = (user->GetBlock() == entry) ? user : entry->GetLastInstruction(); |
| 5769 | entry->InsertInstructionBefore(base_, insert_pos); |
| 5770 | DCHECK(base_ != nullptr); |
| 5771 | } |
| 5772 | |
| 5773 | void ReplaceInput(HInstruction* insn, HConstant* value, int input_index, bool materialize) { |
| 5774 | InitializeConstantAreaPointer(insn); |
| 5775 | HGraph* graph = GetGraph(); |
| 5776 | HBasicBlock* block = insn->GetBlock(); |
| 5777 | HX86LoadFromConstantTable* load_constant = |
| 5778 | new (graph->GetArena()) HX86LoadFromConstantTable(base_, value, materialize); |
| 5779 | block->InsertInstructionBefore(load_constant, insn); |
| 5780 | insn->ReplaceInput(load_constant, input_index); |
| 5781 | } |
| 5782 | |
| 5783 | void HandleInvoke(HInvoke* invoke) { |
| 5784 | // Ensure that we can load FP arguments from the constant area. |
| 5785 | for (size_t i = 0, e = invoke->InputCount(); i < e; i++) { |
| 5786 | HConstant* input = invoke->InputAt(i)->AsConstant(); |
| 5787 | if (input != nullptr && Primitive::IsFloatingPointType(input->GetType())) { |
| 5788 | ReplaceInput(invoke, input, i, true); |
| 5789 | } |
| 5790 | } |
| 5791 | } |
| 5792 | |
| 5793 | // The generated HX86ComputeBaseMethodAddress in the entry block needed as an |
| 5794 | // input to the HX86LoadFromConstantTable instructions. |
| 5795 | HX86ComputeBaseMethodAddress* base_; |
| 5796 | }; |
| 5797 | |
| 5798 | void ConstantAreaFixups::Run() { |
| 5799 | ConstantHandlerVisitor visitor(graph_); |
| 5800 | visitor.VisitInsertionOrder(); |
| 5801 | } |
| 5802 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 5803 | // TODO: target as memory. |
| 5804 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, Primitive::Type type) { |
| 5805 | if (!target.IsValid()) { |
| 5806 | DCHECK(type == Primitive::kPrimVoid); |
| 5807 | return; |
| 5808 | } |
| 5809 | |
| 5810 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 5811 | |
| 5812 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); |
| 5813 | if (target.Equals(return_loc)) { |
| 5814 | return; |
| 5815 | } |
| 5816 | |
| 5817 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged |
| 5818 | // with the else branch. |
| 5819 | if (type == Primitive::kPrimLong) { |
| 5820 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5821 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), Primitive::kPrimInt, nullptr); |
| 5822 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), Primitive::kPrimInt, nullptr); |
| 5823 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5824 | } else { |
| 5825 | // Let the parallel move resolver take care of all of this. |
| 5826 | HParallelMove parallel_move(GetGraph()->GetArena()); |
| 5827 | parallel_move.AddMove(return_loc, target, type, nullptr); |
| 5828 | GetMoveResolver()->EmitNativeCode(¶llel_move); |
| 5829 | } |
| 5830 | } |
| 5831 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5832 | #undef __ |
| 5833 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5834 | } // namespace x86 |
| 5835 | } // namespace art |