| 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" | 
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 20 | #include "class_table.h" | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 21 | #include "code_generator_utils.h" | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 22 | #include "compiled_method.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" | 
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 26 | #include "gc/space/image_space.h" | 
| Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 27 | #include "heap_poisoning.h" | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 28 | #include "intrinsics.h" | 
|  | 29 | #include "intrinsics_x86.h" | 
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 30 | #include "linker/linker_patch.h" | 
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 31 | #include "lock_word.h" | 
| Ian Rogers | 7e70b00 | 2014-10-08 11:47:24 -0700 | [diff] [blame] | 32 | #include "mirror/array-inl.h" | 
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "mirror/class-inl.h" | 
| Nicolas Geoffray | f6e206c | 2014-08-07 20:25:41 +0100 | [diff] [blame] | 34 | #include "thread.h" | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 35 | #include "utils/assembler.h" | 
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 36 | #include "utils/stack_checks.h" | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 37 | #include "utils/x86/assembler_x86.h" | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 38 | #include "utils/x86/managed_register_x86.h" | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 39 |  | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 40 | namespace art { | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 41 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 42 | template<class MirrorType> | 
|  | 43 | class GcRoot; | 
|  | 44 |  | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 45 | namespace x86 { | 
|  | 46 |  | 
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 47 | static constexpr int kCurrentMethodStackOffset = 0; | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 48 | static constexpr Register kMethodRegisterArgument = EAX; | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 49 | static constexpr Register kCoreCalleeSaves[] = { EBP, ESI, EDI }; | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 50 |  | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 51 | static constexpr int kC2ConditionMask = 0x400; | 
|  | 52 |  | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 53 | static constexpr int kFakeReturnRegister = Register(8); | 
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 54 |  | 
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 55 | static constexpr int64_t kDoubleNaN = INT64_C(0x7FF8000000000000); | 
|  | 56 | static constexpr int32_t kFloatNaN = INT32_C(0x7FC00000); | 
|  | 57 |  | 
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 58 | static RegisterSet OneRegInReferenceOutSaveEverythingCallerSaves() { | 
|  | 59 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 60 | RegisterSet caller_saves = RegisterSet::Empty(); | 
|  | 61 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 62 | // TODO: Add GetReturnLocation() to the calling convention so that we can DCHECK() | 
|  | 63 | // that the the kPrimNot result register is the same as the first argument register. | 
|  | 64 | return caller_saves; | 
|  | 65 | } | 
|  | 66 |  | 
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 67 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. | 
|  | 68 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())->  // NOLINT | 
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 69 | #define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kX86PointerSize, x).Int32Value() | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 70 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 71 | class NullCheckSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 72 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 73 | explicit NullCheckSlowPathX86(HNullCheck* instruction) : SlowPathCode(instruction) {} | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 74 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 75 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 76 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 77 | __ Bind(GetEntryLabel()); | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 78 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 79 | // Live registers will be restored in the catch block if caught. | 
|  | 80 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 81 | } | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 82 | x86_codegen->InvokeRuntime(kQuickThrowNullPointer, | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 83 | instruction_, | 
|  | 84 | instruction_->GetDexPc(), | 
|  | 85 | this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 86 | CheckEntrypointTypes<kQuickThrowNullPointer, void, void>(); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 87 | } | 
|  | 88 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 89 | bool IsFatal() const override { return true; } | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 90 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 91 | const char* GetDescription() const override { return "NullCheckSlowPathX86"; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 92 |  | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 93 | private: | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 94 | DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86); | 
|  | 95 | }; | 
|  | 96 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 97 | class DivZeroCheckSlowPathX86 : public SlowPathCode { | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 98 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 99 | explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : SlowPathCode(instruction) {} | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 100 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 101 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 102 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 103 | __ Bind(GetEntryLabel()); | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 104 | x86_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 105 | CheckEntrypointTypes<kQuickThrowDivZero, void, void>(); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 106 | } | 
|  | 107 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 108 | bool IsFatal() const override { return true; } | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 109 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 110 | const char* GetDescription() const override { return "DivZeroCheckSlowPathX86"; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 111 |  | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 112 | private: | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 113 | DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86); | 
|  | 114 | }; | 
|  | 115 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 116 | class DivRemMinusOneSlowPathX86 : public SlowPathCode { | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 117 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 118 | DivRemMinusOneSlowPathX86(HInstruction* instruction, Register reg, bool is_div) | 
|  | 119 | : SlowPathCode(instruction), reg_(reg), is_div_(is_div) {} | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 120 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 121 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 122 | __ Bind(GetEntryLabel()); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 123 | if (is_div_) { | 
|  | 124 | __ negl(reg_); | 
|  | 125 | } else { | 
|  | 126 | __ movl(reg_, Immediate(0)); | 
|  | 127 | } | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 128 | __ jmp(GetExitLabel()); | 
|  | 129 | } | 
|  | 130 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 131 | const char* GetDescription() const override { return "DivRemMinusOneSlowPathX86"; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 132 |  | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 133 | private: | 
|  | 134 | Register reg_; | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 135 | bool is_div_; | 
|  | 136 | DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 137 | }; | 
|  | 138 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 139 | class BoundsCheckSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 140 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 141 | explicit BoundsCheckSlowPathX86(HBoundsCheck* instruction) : SlowPathCode(instruction) {} | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 142 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 143 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 144 | LocationSummary* locations = instruction_->GetLocations(); | 
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 145 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 146 | __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 147 | // We're moving two locations to locations that could overlap, so we need a parallel | 
|  | 148 | // move resolver. | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 149 | if (instruction_->CanThrowIntoCatchBlock()) { | 
|  | 150 | // Live registers will be restored in the catch block if caught. | 
|  | 151 | SaveLiveRegisters(codegen, instruction_->GetLocations()); | 
|  | 152 | } | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 153 |  | 
|  | 154 | // Are we using an array length from memory? | 
|  | 155 | HInstruction* array_length = instruction_->InputAt(1); | 
|  | 156 | Location length_loc = locations->InAt(1); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 157 | InvokeRuntimeCallingConvention calling_convention; | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 158 | if (array_length->IsArrayLength() && array_length->IsEmittedAtUseSite()) { | 
|  | 159 | // Load the array length into our temporary. | 
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 160 | HArrayLength* length = array_length->AsArrayLength(); | 
|  | 161 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(length); | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 162 | Location array_loc = array_length->GetLocations()->InAt(0); | 
|  | 163 | Address array_len(array_loc.AsRegister<Register>(), len_offset); | 
|  | 164 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(1)); | 
|  | 165 | // Check for conflicts with index. | 
|  | 166 | if (length_loc.Equals(locations->InAt(0))) { | 
|  | 167 | // We know we aren't using parameter 2. | 
|  | 168 | length_loc = Location::RegisterLocation(calling_convention.GetRegisterAt(2)); | 
|  | 169 | } | 
|  | 170 | __ movl(length_loc.AsRegister<Register>(), array_len); | 
| Nicolas Geoffray | 0aff3a8 | 2017-10-13 13:12:36 +0100 | [diff] [blame] | 171 | if (mirror::kUseStringCompression && length->IsStringLength()) { | 
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 172 | __ shrl(length_loc.AsRegister<Register>(), Immediate(1)); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 173 | } | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 174 | } | 
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 175 | x86_codegen->EmitParallelMoves( | 
| Serban Constantinescu | 5a6cc49 | 2015-08-13 15:20:25 +0100 | [diff] [blame] | 176 | locations->InAt(0), | 
| Nicolas Geoffray | f0e3937 | 2014-11-12 17:50:07 +0000 | [diff] [blame] | 177 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 178 | DataType::Type::kInt32, | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 179 | length_loc, | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 180 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 181 | DataType::Type::kInt32); | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 182 | QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt() | 
|  | 183 | ? kQuickThrowStringBounds | 
|  | 184 | : kQuickThrowArrayBounds; | 
|  | 185 | x86_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this); | 
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 186 | CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>(); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 187 | CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 190 | bool IsFatal() const override { return true; } | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 191 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 192 | const char* GetDescription() const override { return "BoundsCheckSlowPathX86"; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 193 |  | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 194 | private: | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 195 | DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86); | 
|  | 196 | }; | 
|  | 197 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 198 | class SuspendCheckSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 199 | public: | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 200 | SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 201 | : SlowPathCode(instruction), successor_(successor) {} | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 202 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 203 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 204 | LocationSummary* locations = instruction_->GetLocations(); | 
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 205 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 206 | __ Bind(GetEntryLabel()); | 
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 207 | SaveLiveRegisters(codegen, locations);  // Only saves full width XMM for SIMD. | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 208 | x86_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 209 | CheckEntrypointTypes<kQuickTestSuspend, void, void>(); | 
| Aart Bik | 24b905f | 2017-04-06 09:59:06 -0700 | [diff] [blame] | 210 | RestoreLiveRegisters(codegen, locations);  // Only restores full width XMM for SIMD. | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 211 | if (successor_ == nullptr) { | 
|  | 212 | __ jmp(GetReturnLabel()); | 
|  | 213 | } else { | 
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 214 | __ jmp(x86_codegen->GetLabelOf(successor_)); | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 215 | } | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 216 | } | 
|  | 217 |  | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 218 | Label* GetReturnLabel() { | 
|  | 219 | DCHECK(successor_ == nullptr); | 
|  | 220 | return &return_label_; | 
|  | 221 | } | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 222 |  | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 223 | HBasicBlock* GetSuccessor() const { | 
|  | 224 | return successor_; | 
|  | 225 | } | 
|  | 226 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 227 | const char* GetDescription() const override { return "SuspendCheckSlowPathX86"; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 228 |  | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 229 | private: | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 230 | HBasicBlock* const successor_; | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 231 | Label return_label_; | 
|  | 232 |  | 
|  | 233 | DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86); | 
|  | 234 | }; | 
|  | 235 |  | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 236 | class LoadStringSlowPathX86 : public SlowPathCode { | 
|  | 237 | public: | 
|  | 238 | explicit LoadStringSlowPathX86(HLoadString* instruction): SlowPathCode(instruction) {} | 
|  | 239 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 240 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 241 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 242 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
|  | 243 |  | 
|  | 244 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
|  | 245 | __ Bind(GetEntryLabel()); | 
|  | 246 | SaveLiveRegisters(codegen, locations); | 
|  | 247 |  | 
|  | 248 | InvokeRuntimeCallingConvention calling_convention; | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 249 | const dex::StringIndex string_index = instruction_->AsLoadString()->GetStringIndex(); | 
|  | 250 | __ movl(calling_convention.GetRegisterAt(0), Immediate(string_index.index_)); | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 251 | x86_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this); | 
|  | 252 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); | 
|  | 253 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); | 
|  | 254 | RestoreLiveRegisters(codegen, locations); | 
|  | 255 |  | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 256 | __ jmp(GetExitLabel()); | 
|  | 257 | } | 
|  | 258 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 259 | const char* GetDescription() const override { return "LoadStringSlowPathX86"; } | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 260 |  | 
|  | 261 | private: | 
|  | 262 | DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86); | 
|  | 263 | }; | 
|  | 264 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 265 | class LoadClassSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 266 | public: | 
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 267 | LoadClassSlowPathX86(HLoadClass* cls, HInstruction* at) | 
|  | 268 | : SlowPathCode(at), cls_(cls) { | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 269 | DCHECK(at->IsLoadClass() || at->IsClinitCheck()); | 
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 270 | DCHECK_EQ(instruction_->IsLoadClass(), cls_ == instruction_); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 271 | } | 
|  | 272 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 273 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 274 | LocationSummary* locations = instruction_->GetLocations(); | 
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 275 | Location out = locations->Out(); | 
|  | 276 | const uint32_t dex_pc = instruction_->GetDexPc(); | 
|  | 277 | bool must_resolve_type = instruction_->IsLoadClass() && cls_->MustResolveTypeOnSlowPath(); | 
|  | 278 | bool must_do_clinit = instruction_->IsClinitCheck() || cls_->MustGenerateClinitCheck(); | 
|  | 279 |  | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 280 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
|  | 281 | __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 282 | SaveLiveRegisters(codegen, locations); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 283 |  | 
|  | 284 | InvokeRuntimeCallingConvention calling_convention; | 
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 285 | if (must_resolve_type) { | 
|  | 286 | DCHECK(IsSameDexFile(cls_->GetDexFile(), x86_codegen->GetGraph()->GetDexFile())); | 
|  | 287 | dex::TypeIndex type_index = cls_->GetTypeIndex(); | 
|  | 288 | __ movl(calling_convention.GetRegisterAt(0), Immediate(type_index.index_)); | 
| Vladimir Marko | 9d47925 | 2018-07-24 11:35:20 +0100 | [diff] [blame] | 289 | x86_codegen->InvokeRuntime(kQuickResolveType, instruction_, dex_pc, this); | 
|  | 290 | CheckEntrypointTypes<kQuickResolveType, void*, uint32_t>(); | 
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 291 | // If we also must_do_clinit, the resolved type is now in the correct register. | 
|  | 292 | } else { | 
|  | 293 | DCHECK(must_do_clinit); | 
|  | 294 | Location source = instruction_->IsLoadClass() ? out : locations->InAt(0); | 
|  | 295 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), source); | 
|  | 296 | } | 
|  | 297 | if (must_do_clinit) { | 
|  | 298 | x86_codegen->InvokeRuntime(kQuickInitializeStaticStorage, instruction_, dex_pc, this); | 
|  | 299 | CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, mirror::Class*>(); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 300 | } | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 301 |  | 
|  | 302 | // Move the class to the desired location. | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 303 | if (out.IsValid()) { | 
|  | 304 | DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg())); | 
|  | 305 | x86_codegen->Move32(out, Location::RegisterLocation(EAX)); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 306 | } | 
| Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 307 | RestoreLiveRegisters(codegen, locations); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 308 | __ jmp(GetExitLabel()); | 
|  | 309 | } | 
|  | 310 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 311 | const char* GetDescription() const override { return "LoadClassSlowPathX86"; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 312 |  | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 313 | private: | 
|  | 314 | // The class this slow path will load. | 
|  | 315 | HLoadClass* const cls_; | 
|  | 316 |  | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 317 | DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86); | 
|  | 318 | }; | 
|  | 319 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 320 | class TypeCheckSlowPathX86 : public SlowPathCode { | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 321 | public: | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 322 | TypeCheckSlowPathX86(HInstruction* instruction, bool is_fatal) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 323 | : SlowPathCode(instruction), is_fatal_(is_fatal) {} | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 324 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 325 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 326 | LocationSummary* locations = instruction_->GetLocations(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 327 | DCHECK(instruction_->IsCheckCast() | 
|  | 328 | || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg())); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 329 |  | 
|  | 330 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
|  | 331 | __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 332 |  | 
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 333 | if (kPoisonHeapReferences && | 
|  | 334 | instruction_->IsCheckCast() && | 
|  | 335 | instruction_->AsCheckCast()->GetTypeCheckKind() == TypeCheckKind::kInterfaceCheck) { | 
|  | 336 | // First, unpoison the `cls` reference that was poisoned for direct memory comparison. | 
|  | 337 | __ UnpoisonHeapReference(locations->InAt(1).AsRegister<Register>()); | 
|  | 338 | } | 
|  | 339 |  | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 340 | if (!is_fatal_ || instruction_->CanThrowIntoCatchBlock()) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 341 | SaveLiveRegisters(codegen, locations); | 
|  | 342 | } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 343 |  | 
|  | 344 | // We're moving two locations to locations that could overlap, so we need a parallel | 
|  | 345 | // move resolver. | 
|  | 346 | InvokeRuntimeCallingConvention calling_convention; | 
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 347 | x86_codegen->EmitParallelMoves(locations->InAt(0), | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 348 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 349 | DataType::Type::kReference, | 
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 350 | locations->InAt(1), | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 351 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 352 | DataType::Type::kReference); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 353 | if (instruction_->IsInstanceOf()) { | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 354 | x86_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 355 | instruction_, | 
|  | 356 | instruction_->GetDexPc(), | 
|  | 357 | this); | 
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 358 | CheckEntrypointTypes<kQuickInstanceofNonTrivial, size_t, mirror::Object*, mirror::Class*>(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 359 | } else { | 
|  | 360 | DCHECK(instruction_->IsCheckCast()); | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 361 | x86_codegen->InvokeRuntime(kQuickCheckInstanceOf, | 
|  | 362 | instruction_, | 
|  | 363 | instruction_->GetDexPc(), | 
|  | 364 | this); | 
|  | 365 | CheckEntrypointTypes<kQuickCheckInstanceOf, void, mirror::Object*, mirror::Class*>(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 366 | } | 
|  | 367 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 368 | if (!is_fatal_) { | 
|  | 369 | if (instruction_->IsInstanceOf()) { | 
|  | 370 | x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX)); | 
|  | 371 | } | 
|  | 372 | RestoreLiveRegisters(codegen, locations); | 
| Nicolas Geoffray | 7537437 | 2015-09-17 17:12:19 +0000 | [diff] [blame] | 373 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 374 | __ jmp(GetExitLabel()); | 
|  | 375 | } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 376 | } | 
|  | 377 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 378 | const char* GetDescription() const override { return "TypeCheckSlowPathX86"; } | 
|  | 379 | bool IsFatal() const override { return is_fatal_; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 380 |  | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 381 | private: | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 382 | const bool is_fatal_; | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 383 |  | 
|  | 384 | DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86); | 
|  | 385 | }; | 
|  | 386 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 387 | class DeoptimizationSlowPathX86 : public SlowPathCode { | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 388 | public: | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 389 | explicit DeoptimizationSlowPathX86(HDeoptimize* instruction) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 390 | : SlowPathCode(instruction) {} | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 391 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 392 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 393 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 394 | __ Bind(GetEntryLabel()); | 
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 395 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 396 | SaveLiveRegisters(codegen, locations); | 
|  | 397 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 398 | x86_codegen->Load32BitValue( | 
|  | 399 | calling_convention.GetRegisterAt(0), | 
|  | 400 | static_cast<uint32_t>(instruction_->AsDeoptimize()->GetDeoptimizationKind())); | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 401 | x86_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this); | 
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 402 | CheckEntrypointTypes<kQuickDeoptimize, void, DeoptimizationKind>(); | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 403 | } | 
|  | 404 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 405 | const char* GetDescription() const override { return "DeoptimizationSlowPathX86"; } | 
| Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 406 |  | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 407 | private: | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 408 | DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathX86); | 
|  | 409 | }; | 
|  | 410 |  | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 411 | class ArraySetSlowPathX86 : public SlowPathCode { | 
|  | 412 | public: | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 413 | explicit ArraySetSlowPathX86(HInstruction* instruction) : SlowPathCode(instruction) {} | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 414 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 415 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 416 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 417 | __ Bind(GetEntryLabel()); | 
|  | 418 | SaveLiveRegisters(codegen, locations); | 
|  | 419 |  | 
|  | 420 | InvokeRuntimeCallingConvention calling_convention; | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 421 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 422 | parallel_move.AddMove( | 
|  | 423 | locations->InAt(0), | 
|  | 424 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 425 | DataType::Type::kReference, | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 426 | nullptr); | 
|  | 427 | parallel_move.AddMove( | 
|  | 428 | locations->InAt(1), | 
|  | 429 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 430 | DataType::Type::kInt32, | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 431 | nullptr); | 
|  | 432 | parallel_move.AddMove( | 
|  | 433 | locations->InAt(2), | 
|  | 434 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 435 | DataType::Type::kReference, | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 436 | nullptr); | 
|  | 437 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); | 
|  | 438 |  | 
|  | 439 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 440 | x86_codegen->InvokeRuntime(kQuickAputObject, instruction_, instruction_->GetDexPc(), this); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 441 | CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>(); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 442 | RestoreLiveRegisters(codegen, locations); | 
|  | 443 | __ jmp(GetExitLabel()); | 
|  | 444 | } | 
|  | 445 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 446 | const char* GetDescription() const override { return "ArraySetSlowPathX86"; } | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 447 |  | 
|  | 448 | private: | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 449 | DISALLOW_COPY_AND_ASSIGN(ArraySetSlowPathX86); | 
|  | 450 | }; | 
|  | 451 |  | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 452 | // Slow path marking an object reference `ref` during a read | 
|  | 453 | // barrier. The field `obj.field` in the object `obj` holding this | 
|  | 454 | // reference does not get updated by this slow path after marking (see | 
|  | 455 | // ReadBarrierMarkAndUpdateFieldSlowPathX86 below for that). | 
|  | 456 | // | 
|  | 457 | // This means that after the execution of this slow path, `ref` will | 
|  | 458 | // always be up-to-date, but `obj.field` may not; i.e., after the | 
|  | 459 | // flip, `ref` will be a to-space reference, but `obj.field` will | 
|  | 460 | // probably still be a from-space reference (unless it gets updated by | 
|  | 461 | // another thread, or if another thread installed another object | 
|  | 462 | // reference (different from `ref`) in `obj.field`). | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 463 | class ReadBarrierMarkSlowPathX86 : public SlowPathCode { | 
|  | 464 | public: | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 465 | ReadBarrierMarkSlowPathX86(HInstruction* instruction, | 
|  | 466 | Location ref, | 
|  | 467 | bool unpoison_ref_before_marking) | 
|  | 468 | : SlowPathCode(instruction), | 
|  | 469 | ref_(ref), | 
|  | 470 | unpoison_ref_before_marking_(unpoison_ref_before_marking) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 471 | DCHECK(kEmitCompilerReadBarrier); | 
|  | 472 | } | 
|  | 473 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 474 | const char* GetDescription() const override { return "ReadBarrierMarkSlowPathX86"; } | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 475 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 476 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 477 | LocationSummary* locations = instruction_->GetLocations(); | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 478 | Register ref_reg = ref_.AsRegister<Register>(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 479 | DCHECK(locations->CanCall()); | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 480 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 481 | DCHECK(instruction_->IsInstanceFieldGet() || | 
|  | 482 | instruction_->IsStaticFieldGet() || | 
|  | 483 | instruction_->IsArrayGet() || | 
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 484 | instruction_->IsArraySet() || | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 485 | instruction_->IsLoadClass() || | 
|  | 486 | instruction_->IsLoadString() || | 
|  | 487 | instruction_->IsInstanceOf() || | 
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 488 | instruction_->IsCheckCast() || | 
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 489 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified()) || | 
|  | 490 | (instruction_->IsInvokeStaticOrDirect() && instruction_->GetLocations()->Intrinsified())) | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 491 | << "Unexpected instruction in read barrier marking slow path: " | 
|  | 492 | << instruction_->DebugName(); | 
|  | 493 |  | 
|  | 494 | __ Bind(GetEntryLabel()); | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 495 | if (unpoison_ref_before_marking_) { | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 496 | // Object* ref = ref_addr->AsMirrorPtr() | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 497 | __ MaybeUnpoisonHeapReference(ref_reg); | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 498 | } | 
| Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 499 | // No need to save live registers; it's taken care of by the | 
|  | 500 | // entrypoint. Also, there is no need to update the stack mask, | 
|  | 501 | // as this runtime call will not trigger a garbage collection. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 502 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 503 | DCHECK_NE(ref_reg, ESP); | 
|  | 504 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; | 
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 505 | // "Compact" slow path, saving two moves. | 
|  | 506 | // | 
|  | 507 | // Instead of using the standard runtime calling convention (input | 
|  | 508 | // and output in EAX): | 
|  | 509 | // | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 510 | //   EAX <- ref | 
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 511 | //   EAX <- ReadBarrierMark(EAX) | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 512 | //   ref <- EAX | 
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 513 | // | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 514 | // we just use rX (the register containing `ref`) as input and output | 
| Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 515 | // of a dedicated entrypoint: | 
|  | 516 | // | 
|  | 517 | //   rX <- ReadBarrierMarkRegX(rX) | 
|  | 518 | // | 
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 519 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); | 
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 520 | // This runtime call does not require a stack map. | 
|  | 521 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 522 | __ jmp(GetExitLabel()); | 
|  | 523 | } | 
|  | 524 |  | 
|  | 525 | private: | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 526 | // The location (register) of the marked object reference. | 
|  | 527 | const Location ref_; | 
|  | 528 | // Should the reference in `ref_` be unpoisoned prior to marking it? | 
|  | 529 | const bool unpoison_ref_before_marking_; | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 530 |  | 
|  | 531 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkSlowPathX86); | 
|  | 532 | }; | 
|  | 533 |  | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 534 | // Slow path marking an object reference `ref` during a read barrier, | 
|  | 535 | // and if needed, atomically updating the field `obj.field` in the | 
|  | 536 | // object `obj` holding this reference after marking (contrary to | 
|  | 537 | // ReadBarrierMarkSlowPathX86 above, which never tries to update | 
|  | 538 | // `obj.field`). | 
|  | 539 | // | 
|  | 540 | // This means that after the execution of this slow path, both `ref` | 
|  | 541 | // and `obj.field` will be up-to-date; i.e., after the flip, both will | 
|  | 542 | // hold the same to-space reference (unless another thread installed | 
|  | 543 | // another object reference (different from `ref`) in `obj.field`). | 
|  | 544 | class ReadBarrierMarkAndUpdateFieldSlowPathX86 : public SlowPathCode { | 
|  | 545 | public: | 
|  | 546 | ReadBarrierMarkAndUpdateFieldSlowPathX86(HInstruction* instruction, | 
|  | 547 | Location ref, | 
|  | 548 | Register obj, | 
|  | 549 | const Address& field_addr, | 
|  | 550 | bool unpoison_ref_before_marking, | 
|  | 551 | Register temp) | 
|  | 552 | : SlowPathCode(instruction), | 
|  | 553 | ref_(ref), | 
|  | 554 | obj_(obj), | 
|  | 555 | field_addr_(field_addr), | 
|  | 556 | unpoison_ref_before_marking_(unpoison_ref_before_marking), | 
|  | 557 | temp_(temp) { | 
|  | 558 | DCHECK(kEmitCompilerReadBarrier); | 
|  | 559 | } | 
|  | 560 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 561 | const char* GetDescription() const override { return "ReadBarrierMarkAndUpdateFieldSlowPathX86"; } | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 562 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 563 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 564 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 565 | Register ref_reg = ref_.AsRegister<Register>(); | 
|  | 566 | DCHECK(locations->CanCall()); | 
|  | 567 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(ref_reg)) << ref_reg; | 
|  | 568 | // This slow path is only used by the UnsafeCASObject intrinsic. | 
|  | 569 | DCHECK((instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) | 
|  | 570 | << "Unexpected instruction in read barrier marking and field updating slow path: " | 
|  | 571 | << instruction_->DebugName(); | 
|  | 572 | DCHECK(instruction_->GetLocations()->Intrinsified()); | 
|  | 573 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kUnsafeCASObject); | 
|  | 574 |  | 
|  | 575 | __ Bind(GetEntryLabel()); | 
|  | 576 | if (unpoison_ref_before_marking_) { | 
|  | 577 | // Object* ref = ref_addr->AsMirrorPtr() | 
|  | 578 | __ MaybeUnpoisonHeapReference(ref_reg); | 
|  | 579 | } | 
|  | 580 |  | 
|  | 581 | // Save the old (unpoisoned) reference. | 
|  | 582 | __ movl(temp_, ref_reg); | 
|  | 583 |  | 
|  | 584 | // No need to save live registers; it's taken care of by the | 
|  | 585 | // entrypoint. Also, there is no need to update the stack mask, | 
|  | 586 | // as this runtime call will not trigger a garbage collection. | 
|  | 587 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
|  | 588 | DCHECK_NE(ref_reg, ESP); | 
|  | 589 | DCHECK(0 <= ref_reg && ref_reg < kNumberOfCpuRegisters) << ref_reg; | 
|  | 590 | // "Compact" slow path, saving two moves. | 
|  | 591 | // | 
|  | 592 | // Instead of using the standard runtime calling convention (input | 
|  | 593 | // and output in EAX): | 
|  | 594 | // | 
|  | 595 | //   EAX <- ref | 
|  | 596 | //   EAX <- ReadBarrierMark(EAX) | 
|  | 597 | //   ref <- EAX | 
|  | 598 | // | 
|  | 599 | // we just use rX (the register containing `ref`) as input and output | 
|  | 600 | // of a dedicated entrypoint: | 
|  | 601 | // | 
|  | 602 | //   rX <- ReadBarrierMarkRegX(rX) | 
|  | 603 | // | 
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 604 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(ref_reg); | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 605 | // This runtime call does not require a stack map. | 
|  | 606 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); | 
|  | 607 |  | 
|  | 608 | // If the new reference is different from the old reference, | 
|  | 609 | // update the field in the holder (`*field_addr`). | 
|  | 610 | // | 
|  | 611 | // Note that this field could also hold a different object, if | 
|  | 612 | // another thread had concurrently changed it. In that case, the | 
|  | 613 | // LOCK CMPXCHGL instruction in the compare-and-set (CAS) | 
|  | 614 | // operation below would abort the CAS, leaving the field as-is. | 
|  | 615 | NearLabel done; | 
|  | 616 | __ cmpl(temp_, ref_reg); | 
|  | 617 | __ j(kEqual, &done); | 
|  | 618 |  | 
|  | 619 | // Update the the holder's field atomically.  This may fail if | 
|  | 620 | // mutator updates before us, but it's OK.  This is achieved | 
|  | 621 | // using a strong compare-and-set (CAS) operation with relaxed | 
|  | 622 | // memory synchronization ordering, where the expected value is | 
|  | 623 | // the old reference and the desired value is the new reference. | 
|  | 624 | // This operation is implemented with a 32-bit LOCK CMPXLCHG | 
|  | 625 | // instruction, which requires the expected value (the old | 
|  | 626 | // reference) to be in EAX.  Save EAX beforehand, and move the | 
|  | 627 | // expected value (stored in `temp_`) into EAX. | 
|  | 628 | __ pushl(EAX); | 
|  | 629 | __ movl(EAX, temp_); | 
|  | 630 |  | 
|  | 631 | // Convenience aliases. | 
|  | 632 | Register base = obj_; | 
|  | 633 | Register expected = EAX; | 
|  | 634 | Register value = ref_reg; | 
|  | 635 |  | 
|  | 636 | bool base_equals_value = (base == value); | 
|  | 637 | if (kPoisonHeapReferences) { | 
|  | 638 | if (base_equals_value) { | 
|  | 639 | // If `base` and `value` are the same register location, move | 
|  | 640 | // `value` to a temporary register.  This way, poisoning | 
|  | 641 | // `value` won't invalidate `base`. | 
|  | 642 | value = temp_; | 
|  | 643 | __ movl(value, base); | 
|  | 644 | } | 
|  | 645 |  | 
|  | 646 | // Check that the register allocator did not assign the location | 
|  | 647 | // of `expected` (EAX) to `value` nor to `base`, so that heap | 
|  | 648 | // poisoning (when enabled) works as intended below. | 
|  | 649 | // - If `value` were equal to `expected`, both references would | 
|  | 650 | //   be poisoned twice, meaning they would not be poisoned at | 
|  | 651 | //   all, as heap poisoning uses address negation. | 
|  | 652 | // - If `base` were equal to `expected`, poisoning `expected` | 
|  | 653 | //   would invalidate `base`. | 
|  | 654 | DCHECK_NE(value, expected); | 
|  | 655 | DCHECK_NE(base, expected); | 
|  | 656 |  | 
|  | 657 | __ PoisonHeapReference(expected); | 
|  | 658 | __ PoisonHeapReference(value); | 
|  | 659 | } | 
|  | 660 |  | 
|  | 661 | __ LockCmpxchgl(field_addr_, value); | 
|  | 662 |  | 
|  | 663 | // If heap poisoning is enabled, we need to unpoison the values | 
|  | 664 | // that were poisoned earlier. | 
|  | 665 | if (kPoisonHeapReferences) { | 
|  | 666 | if (base_equals_value) { | 
|  | 667 | // `value` has been moved to a temporary register, no need | 
|  | 668 | // to unpoison it. | 
|  | 669 | } else { | 
|  | 670 | __ UnpoisonHeapReference(value); | 
|  | 671 | } | 
|  | 672 | // No need to unpoison `expected` (EAX), as it is be overwritten below. | 
|  | 673 | } | 
|  | 674 |  | 
|  | 675 | // Restore EAX. | 
|  | 676 | __ popl(EAX); | 
|  | 677 |  | 
|  | 678 | __ Bind(&done); | 
|  | 679 | __ jmp(GetExitLabel()); | 
|  | 680 | } | 
|  | 681 |  | 
|  | 682 | private: | 
|  | 683 | // The location (register) of the marked object reference. | 
|  | 684 | const Location ref_; | 
|  | 685 | // The register containing the object holding the marked object reference field. | 
|  | 686 | const Register obj_; | 
|  | 687 | // The address of the marked reference field.  The base of this address must be `obj_`. | 
|  | 688 | const Address field_addr_; | 
|  | 689 |  | 
|  | 690 | // Should the reference in `ref_` be unpoisoned prior to marking it? | 
|  | 691 | const bool unpoison_ref_before_marking_; | 
|  | 692 |  | 
|  | 693 | const Register temp_; | 
|  | 694 |  | 
|  | 695 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierMarkAndUpdateFieldSlowPathX86); | 
|  | 696 | }; | 
|  | 697 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 698 | // Slow path generating a read barrier for a heap reference. | 
|  | 699 | class ReadBarrierForHeapReferenceSlowPathX86 : public SlowPathCode { | 
|  | 700 | public: | 
|  | 701 | ReadBarrierForHeapReferenceSlowPathX86(HInstruction* instruction, | 
|  | 702 | Location out, | 
|  | 703 | Location ref, | 
|  | 704 | Location obj, | 
|  | 705 | uint32_t offset, | 
|  | 706 | Location index) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 707 | : SlowPathCode(instruction), | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 708 | out_(out), | 
|  | 709 | ref_(ref), | 
|  | 710 | obj_(obj), | 
|  | 711 | offset_(offset), | 
|  | 712 | index_(index) { | 
|  | 713 | DCHECK(kEmitCompilerReadBarrier); | 
|  | 714 | // If `obj` is equal to `out` or `ref`, it means the initial object | 
|  | 715 | // has been overwritten by (or after) the heap object reference load | 
|  | 716 | // to be instrumented, e.g.: | 
|  | 717 | // | 
|  | 718 | //   __ movl(out, Address(out, offset)); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 719 | //   codegen_->GenerateReadBarrierSlow(instruction, out_loc, out_loc, out_loc, offset); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 720 | // | 
|  | 721 | // In that case, we have lost the information about the original | 
|  | 722 | // object, and the emitted read barrier cannot work properly. | 
|  | 723 | DCHECK(!obj.Equals(out)) << "obj=" << obj << " out=" << out; | 
|  | 724 | DCHECK(!obj.Equals(ref)) << "obj=" << obj << " ref=" << ref; | 
|  | 725 | } | 
|  | 726 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 727 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 728 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
|  | 729 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 730 | Register reg_out = out_.AsRegister<Register>(); | 
|  | 731 | DCHECK(locations->CanCall()); | 
|  | 732 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); | 
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 733 | DCHECK(instruction_->IsInstanceFieldGet() || | 
|  | 734 | instruction_->IsStaticFieldGet() || | 
|  | 735 | instruction_->IsArrayGet() || | 
|  | 736 | instruction_->IsInstanceOf() || | 
|  | 737 | instruction_->IsCheckCast() || | 
| Andreas Gampe | d9911ee | 2017-03-27 13:27:24 -0700 | [diff] [blame] | 738 | (instruction_->IsInvokeVirtual() && instruction_->GetLocations()->Intrinsified())) | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 739 | << "Unexpected instruction in read barrier for heap reference slow path: " | 
|  | 740 | << instruction_->DebugName(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 741 |  | 
|  | 742 | __ Bind(GetEntryLabel()); | 
|  | 743 | SaveLiveRegisters(codegen, locations); | 
|  | 744 |  | 
|  | 745 | // We may have to change the index's value, but as `index_` is a | 
|  | 746 | // constant member (like other "inputs" of this slow path), | 
|  | 747 | // introduce a copy of it, `index`. | 
|  | 748 | Location index = index_; | 
|  | 749 | if (index_.IsValid()) { | 
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 750 | // Handle `index_` for HArrayGet and UnsafeGetObject/UnsafeGetObjectVolatile intrinsics. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 751 | if (instruction_->IsArrayGet()) { | 
|  | 752 | // Compute the actual memory offset and store it in `index`. | 
|  | 753 | Register index_reg = index_.AsRegister<Register>(); | 
|  | 754 | DCHECK(locations->GetLiveRegisters()->ContainsCoreRegister(index_reg)); | 
|  | 755 | if (codegen->IsCoreCalleeSaveRegister(index_reg)) { | 
|  | 756 | // We are about to change the value of `index_reg` (see the | 
|  | 757 | // calls to art::x86::X86Assembler::shll and | 
|  | 758 | // art::x86::X86Assembler::AddImmediate below), but it has | 
|  | 759 | // not been saved by the previous call to | 
|  | 760 | // art::SlowPathCode::SaveLiveRegisters, as it is a | 
|  | 761 | // callee-save register -- | 
|  | 762 | // art::SlowPathCode::SaveLiveRegisters does not consider | 
|  | 763 | // callee-save registers, as it has been designed with the | 
|  | 764 | // assumption that callee-save registers are supposed to be | 
|  | 765 | // handled by the called function.  So, as a callee-save | 
|  | 766 | // register, `index_reg` _would_ eventually be saved onto | 
|  | 767 | // the stack, but it would be too late: we would have | 
|  | 768 | // changed its value earlier.  Therefore, we manually save | 
|  | 769 | // it here into another freely available register, | 
|  | 770 | // `free_reg`, chosen of course among the caller-save | 
|  | 771 | // registers (as a callee-save `free_reg` register would | 
|  | 772 | // exhibit the same problem). | 
|  | 773 | // | 
|  | 774 | // Note we could have requested a temporary register from | 
|  | 775 | // the register allocator instead; but we prefer not to, as | 
|  | 776 | // this is a slow path, and we know we can find a | 
|  | 777 | // caller-save register that is available. | 
|  | 778 | Register free_reg = FindAvailableCallerSaveRegister(codegen); | 
|  | 779 | __ movl(free_reg, index_reg); | 
|  | 780 | index_reg = free_reg; | 
|  | 781 | index = Location::RegisterLocation(index_reg); | 
|  | 782 | } else { | 
|  | 783 | // The initial register stored in `index_` has already been | 
|  | 784 | // saved in the call to art::SlowPathCode::SaveLiveRegisters | 
|  | 785 | // (as it is not a callee-save register), so we can freely | 
|  | 786 | // use it. | 
|  | 787 | } | 
|  | 788 | // Shifting the index value contained in `index_reg` by the scale | 
|  | 789 | // factor (2) cannot overflow in practice, as the runtime is | 
|  | 790 | // unable to allocate object arrays with a size larger than | 
|  | 791 | // 2^26 - 1 (that is, 2^28 - 4 bytes). | 
|  | 792 | __ shll(index_reg, Immediate(TIMES_4)); | 
|  | 793 | static_assert( | 
|  | 794 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), | 
|  | 795 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); | 
|  | 796 | __ AddImmediate(index_reg, Immediate(offset_)); | 
|  | 797 | } else { | 
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 798 | // In the case of the UnsafeGetObject/UnsafeGetObjectVolatile | 
|  | 799 | // intrinsics, `index_` is not shifted by a scale factor of 2 | 
|  | 800 | // (as in the case of ArrayGet), as it is actually an offset | 
|  | 801 | // to an object field within an object. | 
|  | 802 | DCHECK(instruction_->IsInvoke()) << instruction_->DebugName(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 803 | DCHECK(instruction_->GetLocations()->Intrinsified()); | 
|  | 804 | DCHECK((instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObject) || | 
|  | 805 | (instruction_->AsInvoke()->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile)) | 
|  | 806 | << instruction_->AsInvoke()->GetIntrinsic(); | 
|  | 807 | DCHECK_EQ(offset_, 0U); | 
|  | 808 | DCHECK(index_.IsRegisterPair()); | 
|  | 809 | // UnsafeGet's offset location is a register pair, the low | 
|  | 810 | // part contains the correct offset. | 
|  | 811 | index = index_.ToLow(); | 
|  | 812 | } | 
|  | 813 | } | 
|  | 814 |  | 
|  | 815 | // We're moving two or three locations to locations that could | 
|  | 816 | // overlap, so we need a parallel move resolver. | 
|  | 817 | InvokeRuntimeCallingConvention calling_convention; | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 818 | HParallelMove parallel_move(codegen->GetGraph()->GetAllocator()); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 819 | parallel_move.AddMove(ref_, | 
|  | 820 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 821 | DataType::Type::kReference, | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 822 | nullptr); | 
|  | 823 | parallel_move.AddMove(obj_, | 
|  | 824 | Location::RegisterLocation(calling_convention.GetRegisterAt(1)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 825 | DataType::Type::kReference, | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 826 | nullptr); | 
|  | 827 | if (index.IsValid()) { | 
|  | 828 | parallel_move.AddMove(index, | 
|  | 829 | Location::RegisterLocation(calling_convention.GetRegisterAt(2)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 830 | DataType::Type::kInt32, | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 831 | nullptr); | 
|  | 832 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); | 
|  | 833 | } else { | 
|  | 834 | codegen->GetMoveResolver()->EmitNativeCode(¶llel_move); | 
|  | 835 | __ movl(calling_convention.GetRegisterAt(2), Immediate(offset_)); | 
|  | 836 | } | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 837 | x86_codegen->InvokeRuntime(kQuickReadBarrierSlow, instruction_, instruction_->GetDexPc(), this); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 838 | CheckEntrypointTypes< | 
|  | 839 | kQuickReadBarrierSlow, mirror::Object*, mirror::Object*, mirror::Object*, uint32_t>(); | 
|  | 840 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); | 
|  | 841 |  | 
|  | 842 | RestoreLiveRegisters(codegen, locations); | 
|  | 843 | __ jmp(GetExitLabel()); | 
|  | 844 | } | 
|  | 845 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 846 | const char* GetDescription() const override { return "ReadBarrierForHeapReferenceSlowPathX86"; } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 847 |  | 
|  | 848 | private: | 
|  | 849 | Register FindAvailableCallerSaveRegister(CodeGenerator* codegen) { | 
|  | 850 | size_t ref = static_cast<int>(ref_.AsRegister<Register>()); | 
|  | 851 | size_t obj = static_cast<int>(obj_.AsRegister<Register>()); | 
|  | 852 | for (size_t i = 0, e = codegen->GetNumberOfCoreRegisters(); i < e; ++i) { | 
|  | 853 | if (i != ref && i != obj && !codegen->IsCoreCalleeSaveRegister(i)) { | 
|  | 854 | return static_cast<Register>(i); | 
|  | 855 | } | 
|  | 856 | } | 
|  | 857 | // We shall never fail to find a free caller-save register, as | 
|  | 858 | // there are more than two core caller-save registers on x86 | 
|  | 859 | // (meaning it is possible to find one which is different from | 
|  | 860 | // `ref` and `obj`). | 
|  | 861 | DCHECK_GT(codegen->GetNumberOfCoreCallerSaveRegisters(), 2u); | 
|  | 862 | LOG(FATAL) << "Could not find a free caller-save register"; | 
|  | 863 | UNREACHABLE(); | 
|  | 864 | } | 
|  | 865 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 866 | const Location out_; | 
|  | 867 | const Location ref_; | 
|  | 868 | const Location obj_; | 
|  | 869 | const uint32_t offset_; | 
|  | 870 | // An additional location containing an index to an array. | 
|  | 871 | // Only used for HArrayGet and the UnsafeGetObject & | 
|  | 872 | // UnsafeGetObjectVolatile intrinsics. | 
|  | 873 | const Location index_; | 
|  | 874 |  | 
|  | 875 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForHeapReferenceSlowPathX86); | 
|  | 876 | }; | 
|  | 877 |  | 
|  | 878 | // Slow path generating a read barrier for a GC root. | 
|  | 879 | class ReadBarrierForRootSlowPathX86 : public SlowPathCode { | 
|  | 880 | public: | 
|  | 881 | ReadBarrierForRootSlowPathX86(HInstruction* instruction, Location out, Location root) | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 882 | : SlowPathCode(instruction), out_(out), root_(root) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 883 | DCHECK(kEmitCompilerReadBarrier); | 
|  | 884 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 885 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 886 | void EmitNativeCode(CodeGenerator* codegen) override { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 887 | LocationSummary* locations = instruction_->GetLocations(); | 
|  | 888 | Register reg_out = out_.AsRegister<Register>(); | 
|  | 889 | DCHECK(locations->CanCall()); | 
|  | 890 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(reg_out)); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 891 | DCHECK(instruction_->IsLoadClass() || instruction_->IsLoadString()) | 
|  | 892 | << "Unexpected instruction in read barrier for GC root slow path: " | 
|  | 893 | << instruction_->DebugName(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 894 |  | 
|  | 895 | __ Bind(GetEntryLabel()); | 
|  | 896 | SaveLiveRegisters(codegen, locations); | 
|  | 897 |  | 
|  | 898 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 899 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); | 
|  | 900 | x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), root_); | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 901 | x86_codegen->InvokeRuntime(kQuickReadBarrierForRootSlow, | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 902 | instruction_, | 
|  | 903 | instruction_->GetDexPc(), | 
|  | 904 | this); | 
|  | 905 | CheckEntrypointTypes<kQuickReadBarrierForRootSlow, mirror::Object*, GcRoot<mirror::Object>*>(); | 
|  | 906 | x86_codegen->Move32(out_, Location::RegisterLocation(EAX)); | 
|  | 907 |  | 
|  | 908 | RestoreLiveRegisters(codegen, locations); | 
|  | 909 | __ jmp(GetExitLabel()); | 
|  | 910 | } | 
|  | 911 |  | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 912 | const char* GetDescription() const override { return "ReadBarrierForRootSlowPathX86"; } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 913 |  | 
|  | 914 | private: | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 915 | const Location out_; | 
|  | 916 | const Location root_; | 
|  | 917 |  | 
|  | 918 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierForRootSlowPathX86); | 
|  | 919 | }; | 
|  | 920 |  | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 921 | #undef __ | 
| Roland Levillain | 7cbd27f | 2016-08-11 23:53:33 +0100 | [diff] [blame] | 922 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. | 
|  | 923 | #define __ down_cast<X86Assembler*>(GetAssembler())->  // NOLINT | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 924 |  | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 925 | inline Condition X86Condition(IfCondition cond) { | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 926 | switch (cond) { | 
|  | 927 | case kCondEQ: return kEqual; | 
|  | 928 | case kCondNE: return kNotEqual; | 
|  | 929 | case kCondLT: return kLess; | 
|  | 930 | case kCondLE: return kLessEqual; | 
|  | 931 | case kCondGT: return kGreater; | 
|  | 932 | case kCondGE: return kGreaterEqual; | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 933 | case kCondB:  return kBelow; | 
|  | 934 | case kCondBE: return kBelowEqual; | 
|  | 935 | case kCondA:  return kAbove; | 
|  | 936 | case kCondAE: return kAboveEqual; | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 937 | } | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 938 | LOG(FATAL) << "Unreachable"; | 
|  | 939 | UNREACHABLE(); | 
|  | 940 | } | 
|  | 941 |  | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 942 | // Maps signed condition to unsigned condition and FP condition to x86 name. | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 943 | inline Condition X86UnsignedOrFPCondition(IfCondition cond) { | 
|  | 944 | switch (cond) { | 
|  | 945 | case kCondEQ: return kEqual; | 
|  | 946 | case kCondNE: return kNotEqual; | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 947 | // Signed to unsigned, and FP to x86 name. | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 948 | case kCondLT: return kBelow; | 
|  | 949 | case kCondLE: return kBelowEqual; | 
|  | 950 | case kCondGT: return kAbove; | 
|  | 951 | case kCondGE: return kAboveEqual; | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 952 | // Unsigned remain unchanged. | 
|  | 953 | case kCondB:  return kBelow; | 
|  | 954 | case kCondBE: return kBelowEqual; | 
|  | 955 | case kCondA:  return kAbove; | 
|  | 956 | case kCondAE: return kAboveEqual; | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 957 | } | 
|  | 958 | LOG(FATAL) << "Unreachable"; | 
|  | 959 | UNREACHABLE(); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 960 | } | 
|  | 961 |  | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 962 | void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const { | 
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 963 | stream << Register(reg); | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 964 | } | 
|  | 965 |  | 
|  | 966 | void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const { | 
| David Brazdil | c7465286 | 2015-05-13 17:50:09 +0100 | [diff] [blame] | 967 | stream << XmmRegister(reg); | 
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 968 | } | 
|  | 969 |  | 
| Vladimir Marko | a043111 | 2018-06-25 09:32:54 +0100 | [diff] [blame] | 970 | const X86InstructionSetFeatures& CodeGeneratorX86::GetInstructionSetFeatures() const { | 
|  | 971 | return *GetCompilerOptions().GetInstructionSetFeatures()->AsX86InstructionSetFeatures(); | 
|  | 972 | } | 
|  | 973 |  | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 974 | size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 975 | __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id)); | 
|  | 976 | return kX86WordSize; | 
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 977 | } | 
|  | 978 |  | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 979 | size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) { | 
|  | 980 | __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index)); | 
|  | 981 | return kX86WordSize; | 
| Nicolas Geoffray | 3bca0df | 2014-09-19 11:01:00 +0100 | [diff] [blame] | 982 | } | 
|  | 983 |  | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 984 | size_t CodeGeneratorX86::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 985 | if (GetGraph()->HasSIMD()) { | 
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 986 | __ movups(Address(ESP, stack_index), XmmRegister(reg_id)); | 
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 987 | } else { | 
|  | 988 | __ movsd(Address(ESP, stack_index), XmmRegister(reg_id)); | 
|  | 989 | } | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 990 | return GetFloatingPointSpillSlotSize(); | 
|  | 991 | } | 
|  | 992 |  | 
|  | 993 | size_t CodeGeneratorX86::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) { | 
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 994 | if (GetGraph()->HasSIMD()) { | 
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 995 | __ movups(XmmRegister(reg_id), Address(ESP, stack_index)); | 
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 996 | } else { | 
|  | 997 | __ movsd(XmmRegister(reg_id), Address(ESP, stack_index)); | 
|  | 998 | } | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 999 | return GetFloatingPointSpillSlotSize(); | 
|  | 1000 | } | 
|  | 1001 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1002 | void CodeGeneratorX86::InvokeRuntime(QuickEntrypointEnum entrypoint, | 
|  | 1003 | HInstruction* instruction, | 
|  | 1004 | uint32_t dex_pc, | 
|  | 1005 | SlowPathCode* slow_path) { | 
| Alexandre Rames | 91a6516 | 2016-09-19 13:54:30 +0100 | [diff] [blame] | 1006 | ValidateInvokeRuntime(entrypoint, instruction, slow_path); | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1007 | GenerateInvokeRuntime(GetThreadOffset<kX86PointerSize>(entrypoint).Int32Value()); | 
|  | 1008 | if (EntrypointRequiresStackMap(entrypoint)) { | 
|  | 1009 | RecordPcInfo(instruction, dex_pc, slow_path); | 
|  | 1010 | } | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 1011 | } | 
|  | 1012 |  | 
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1013 | void CodeGeneratorX86::InvokeRuntimeWithoutRecordingPcInfo(int32_t entry_point_offset, | 
|  | 1014 | HInstruction* instruction, | 
|  | 1015 | SlowPathCode* slow_path) { | 
|  | 1016 | ValidateInvokeRuntimeWithoutRecordingPcInfo(instruction, slow_path); | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1017 | GenerateInvokeRuntime(entry_point_offset); | 
|  | 1018 | } | 
|  | 1019 |  | 
|  | 1020 | void CodeGeneratorX86::GenerateInvokeRuntime(int32_t entry_point_offset) { | 
| Roland Levillain | dec8f63 | 2016-07-22 17:10:06 +0100 | [diff] [blame] | 1021 | __ fs()->call(Address::Absolute(entry_point_offset)); | 
|  | 1022 | } | 
|  | 1023 |  | 
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 1024 | CodeGeneratorX86::CodeGeneratorX86(HGraph* graph, | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1025 | const CompilerOptions& compiler_options, | 
|  | 1026 | OptimizingCompilerStats* stats) | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1027 | : CodeGenerator(graph, | 
|  | 1028 | kNumberOfCpuRegisters, | 
|  | 1029 | kNumberOfXmmRegisters, | 
|  | 1030 | kNumberOfRegisterPairs, | 
|  | 1031 | ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves), | 
|  | 1032 | arraysize(kCoreCalleeSaves)) | 
|  | 1033 | | (1 << kFakeReturnRegister), | 
| Serban Constantinescu | ecc4366 | 2015-08-13 13:33:12 +0100 | [diff] [blame] | 1034 | 0, | 
|  | 1035 | compiler_options, | 
|  | 1036 | stats), | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 1037 | block_labels_(nullptr), | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1038 | location_builder_(graph, this), | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1039 | instruction_visitor_(graph, this), | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1040 | move_resolver_(graph->GetAllocator(), this), | 
|  | 1041 | assembler_(graph->GetAllocator()), | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1042 | boot_image_method_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
|  | 1043 | method_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
|  | 1044 | boot_image_type_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
|  | 1045 | type_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 1046 | boot_image_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1047 | string_bss_entry_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 1048 | boot_image_intrinsic_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1049 | jit_string_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
|  | 1050 | jit_class_patches_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
| Vladimir Marko | 93205e3 | 2016-04-13 11:59:46 +0100 | [diff] [blame] | 1051 | constant_area_start_(-1), | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1052 | fixups_to_jump_tables_(graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)), | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1053 | method_address_offset_(std::less<uint32_t>(), | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1054 | graph->GetAllocator()->Adapter(kArenaAllocCodeGenerator)) { | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1055 | // Use a fake return address register to mimic Quick. | 
|  | 1056 | AddAllocatedRegister(Location::RegisterLocation(kFakeReturnRegister)); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1057 | } | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1058 |  | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 1059 | void CodeGeneratorX86::SetupBlockedRegisters() const { | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1060 | // Stack register is always reserved. | 
| Nicolas Geoffray | 71175b7 | 2014-10-09 22:13:55 +0100 | [diff] [blame] | 1061 | blocked_core_registers_[ESP] = true; | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1062 | } | 
|  | 1063 |  | 
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1064 | InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen) | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1065 | : InstructionCodeGenerator(graph, codegen), | 
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1066 | assembler_(codegen->GetAssembler()), | 
|  | 1067 | codegen_(codegen) {} | 
|  | 1068 |  | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1069 | static dwarf::Reg DWARFReg(Register reg) { | 
| David Srbecky | 9d8606d | 2015-04-12 09:35:32 +0100 | [diff] [blame] | 1070 | return dwarf::Reg::X86Core(static_cast<int>(reg)); | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1071 | } | 
|  | 1072 |  | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1073 | void CodeGeneratorX86::GenerateFrameEntry() { | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1074 | __ cfi().SetCurrentCFAOffset(kX86WordSize);  // return address | 
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 1075 | __ Bind(&frame_entry_label_); | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 1076 | bool skip_overflow_check = | 
|  | 1077 | IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86); | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1078 | DCHECK(GetCompilerOptions().GetImplicitStackOverflowChecks()); | 
| Calin Juravle | 93edf73 | 2015-01-20 20:14:07 +0000 | [diff] [blame] | 1079 |  | 
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1080 | if (GetCompilerOptions().CountHotnessInCompiledCode()) { | 
|  | 1081 | __ addw(Address(kMethodRegisterArgument, ArtMethod::HotnessCountOffset().Int32Value()), | 
|  | 1082 | Immediate(1)); | 
|  | 1083 | } | 
|  | 1084 |  | 
| Nicolas Geoffray | d97dc40 | 2015-01-22 13:50:01 +0000 | [diff] [blame] | 1085 | if (!skip_overflow_check) { | 
| Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 1086 | size_t reserved_bytes = GetStackOverflowReservedBytes(InstructionSet::kX86); | 
|  | 1087 | __ testl(EAX, Address(ESP, -static_cast<int32_t>(reserved_bytes))); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1088 | RecordPcInfo(nullptr, 0); | 
| Nicolas Geoffray | 397f2e4 | 2014-07-23 12:57:19 +0100 | [diff] [blame] | 1089 | } | 
|  | 1090 |  | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1091 | if (HasEmptyFrame()) { | 
|  | 1092 | return; | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1093 | } | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1094 |  | 
|  | 1095 | for (int i = arraysize(kCoreCalleeSaves) - 1; i >= 0; --i) { | 
|  | 1096 | Register reg = kCoreCalleeSaves[i]; | 
|  | 1097 | if (allocated_registers_.ContainsCoreRegister(reg)) { | 
|  | 1098 | __ pushl(reg); | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1099 | __ cfi().AdjustCFAOffset(kX86WordSize); | 
|  | 1100 | __ cfi().RelOffset(DWARFReg(reg), 0); | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1101 | } | 
|  | 1102 | } | 
|  | 1103 |  | 
| David Srbecky | c6b4dd8 | 2015-04-07 20:32:43 +0100 | [diff] [blame] | 1104 | int adjust = GetFrameSize() - FrameEntrySpillSize(); | 
|  | 1105 | __ subl(ESP, Immediate(adjust)); | 
|  | 1106 | __ cfi().AdjustCFAOffset(adjust); | 
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 1107 | // Save the current method if we need it. Note that we do not | 
|  | 1108 | // do this in HCurrentMethod, as the instruction might have been removed | 
|  | 1109 | // in the SSA graph. | 
|  | 1110 | if (RequiresCurrentMethod()) { | 
|  | 1111 | __ movl(Address(ESP, kCurrentMethodStackOffset), kMethodRegisterArgument); | 
|  | 1112 | } | 
| Nicolas Geoffray | f789353 | 2017-06-15 12:34:36 +0100 | [diff] [blame] | 1113 |  | 
|  | 1114 | if (GetGraph()->HasShouldDeoptimizeFlag()) { | 
|  | 1115 | // Initialize should_deoptimize flag to 0. | 
|  | 1116 | __ movl(Address(ESP, GetStackOffsetOfShouldDeoptimizeFlag()), Immediate(0)); | 
|  | 1117 | } | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1118 | } | 
|  | 1119 |  | 
|  | 1120 | void CodeGeneratorX86::GenerateFrameExit() { | 
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1121 | __ cfi().RememberState(); | 
|  | 1122 | if (!HasEmptyFrame()) { | 
|  | 1123 | int adjust = GetFrameSize() - FrameEntrySpillSize(); | 
|  | 1124 | __ addl(ESP, Immediate(adjust)); | 
|  | 1125 | __ cfi().AdjustCFAOffset(-adjust); | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1126 |  | 
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1127 | for (size_t i = 0; i < arraysize(kCoreCalleeSaves); ++i) { | 
|  | 1128 | Register reg = kCoreCalleeSaves[i]; | 
|  | 1129 | if (allocated_registers_.ContainsCoreRegister(reg)) { | 
|  | 1130 | __ popl(reg); | 
|  | 1131 | __ cfi().AdjustCFAOffset(-static_cast<int>(kX86WordSize)); | 
|  | 1132 | __ cfi().Restore(DWARFReg(reg)); | 
|  | 1133 | } | 
| Mark Mendell | 5f87418 | 2015-03-04 15:42:45 -0500 | [diff] [blame] | 1134 | } | 
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1135 | } | 
| David Srbecky | c34dc93 | 2015-04-12 09:27:43 +0100 | [diff] [blame] | 1136 | __ ret(); | 
|  | 1137 | __ cfi().RestoreState(); | 
|  | 1138 | __ cfi().DefCFAOffset(GetFrameSize()); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1139 | } | 
|  | 1140 |  | 
| Nicolas Geoffray | 92a73ae | 2014-10-16 11:12:52 +0100 | [diff] [blame] | 1141 | void CodeGeneratorX86::Bind(HBasicBlock* block) { | 
|  | 1142 | __ Bind(GetLabelOf(block)); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1143 | } | 
|  | 1144 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1145 | Location InvokeDexCallingConventionVisitorX86::GetReturnLocation(DataType::Type type) const { | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1146 | switch (type) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1147 | case DataType::Type::kReference: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1148 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1149 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1150 | case DataType::Type::kInt8: | 
|  | 1151 | case DataType::Type::kUint16: | 
|  | 1152 | case DataType::Type::kInt16: | 
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1153 | case DataType::Type::kUint32: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1154 | case DataType::Type::kInt32: | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1155 | return Location::RegisterLocation(EAX); | 
|  | 1156 |  | 
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1157 | case DataType::Type::kUint64: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1158 | case DataType::Type::kInt64: | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1159 | return Location::RegisterPairLocation(EAX, EDX); | 
|  | 1160 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1161 | case DataType::Type::kVoid: | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1162 | return Location::NoLocation(); | 
|  | 1163 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1164 | case DataType::Type::kFloat64: | 
|  | 1165 | case DataType::Type::kFloat32: | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1166 | return Location::FpuRegisterLocation(XMM0); | 
|  | 1167 | } | 
| Nicolas Geoffray | 0d1652e | 2015-06-03 12:12:19 +0100 | [diff] [blame] | 1168 |  | 
|  | 1169 | UNREACHABLE(); | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 1170 | } | 
|  | 1171 |  | 
|  | 1172 | Location InvokeDexCallingConventionVisitorX86::GetMethodLocation() const { | 
|  | 1173 | return Location::RegisterLocation(kMethodRegisterArgument); | 
|  | 1174 | } | 
|  | 1175 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1176 | Location InvokeDexCallingConventionVisitorX86::GetNextLocation(DataType::Type type) { | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1177 | switch (type) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1178 | case DataType::Type::kReference: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1179 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1180 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1181 | case DataType::Type::kInt8: | 
|  | 1182 | case DataType::Type::kUint16: | 
|  | 1183 | case DataType::Type::kInt16: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1184 | case DataType::Type::kInt32: { | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1185 | uint32_t index = gp_index_++; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1186 | stack_index_++; | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1187 | if (index < calling_convention.GetNumberOfRegisters()) { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1188 | return Location::RegisterLocation(calling_convention.GetRegisterAt(index)); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1189 | } else { | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1190 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); | 
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1191 | } | 
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1192 | } | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1193 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1194 | case DataType::Type::kInt64: { | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1195 | uint32_t index = gp_index_; | 
|  | 1196 | gp_index_ += 2; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1197 | stack_index_ += 2; | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1198 | if (index + 1 < calling_convention.GetNumberOfRegisters()) { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1199 | X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair( | 
|  | 1200 | calling_convention.GetRegisterPairAt(index)); | 
|  | 1201 | return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh()); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1202 | } else { | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1203 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); | 
|  | 1204 | } | 
|  | 1205 | } | 
|  | 1206 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1207 | case DataType::Type::kFloat32: { | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1208 | uint32_t index = float_index_++; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1209 | stack_index_++; | 
|  | 1210 | if (index < calling_convention.GetNumberOfFpuRegisters()) { | 
|  | 1211 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); | 
|  | 1212 | } else { | 
|  | 1213 | return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 1)); | 
|  | 1214 | } | 
|  | 1215 | } | 
|  | 1216 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1217 | case DataType::Type::kFloat64: { | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 1218 | uint32_t index = float_index_++; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 1219 | stack_index_ += 2; | 
|  | 1220 | if (index < calling_convention.GetNumberOfFpuRegisters()) { | 
|  | 1221 | return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(index)); | 
|  | 1222 | } else { | 
|  | 1223 | return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index_ - 2)); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1224 | } | 
|  | 1225 | } | 
|  | 1226 |  | 
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 1227 | case DataType::Type::kUint32: | 
|  | 1228 | case DataType::Type::kUint64: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1229 | case DataType::Type::kVoid: | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1230 | LOG(FATAL) << "Unexpected parameter type " << type; | 
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 1231 | UNREACHABLE(); | 
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1232 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1233 | return Location::NoLocation(); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 1234 | } | 
| Nicolas Geoffray | db928fc | 2014-04-16 17:38:32 +0100 | [diff] [blame] | 1235 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1236 | void CodeGeneratorX86::Move32(Location destination, Location source) { | 
|  | 1237 | if (source.Equals(destination)) { | 
|  | 1238 | return; | 
|  | 1239 | } | 
|  | 1240 | if (destination.IsRegister()) { | 
|  | 1241 | if (source.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1242 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1243 | } else if (source.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1244 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1245 | } else { | 
|  | 1246 | DCHECK(source.IsStackSlot()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1247 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1248 | } | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1249 | } else if (destination.IsFpuRegister()) { | 
|  | 1250 | if (source.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1251 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1252 | } else if (source.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1253 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1254 | } else { | 
|  | 1255 | DCHECK(source.IsStackSlot()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1256 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1257 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1258 | } else { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1259 | DCHECK(destination.IsStackSlot()) << destination; | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1260 | if (source.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1261 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1262 | } else if (source.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1263 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1264 | } else if (source.IsConstant()) { | 
|  | 1265 | HConstant* constant = source.GetConstant(); | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1266 | int32_t value = GetInt32ValueOf(constant); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1267 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1268 | } else { | 
|  | 1269 | DCHECK(source.IsStackSlot()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 1270 | __ pushl(Address(ESP, source.GetStackIndex())); | 
|  | 1271 | __ popl(Address(ESP, destination.GetStackIndex())); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1272 | } | 
|  | 1273 | } | 
|  | 1274 | } | 
|  | 1275 |  | 
|  | 1276 | void CodeGeneratorX86::Move64(Location destination, Location source) { | 
|  | 1277 | if (source.Equals(destination)) { | 
|  | 1278 | return; | 
|  | 1279 | } | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1280 | if (destination.IsRegisterPair()) { | 
|  | 1281 | if (source.IsRegisterPair()) { | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1282 | EmitParallelMoves( | 
|  | 1283 | Location::RegisterLocation(source.AsRegisterPairHigh<Register>()), | 
|  | 1284 | Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1285 | DataType::Type::kInt32, | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1286 | Location::RegisterLocation(source.AsRegisterPairLow<Register>()), | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1287 | Location::RegisterLocation(destination.AsRegisterPairLow<Register>()), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1288 | DataType::Type::kInt32); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1289 | } else if (source.IsFpuRegister()) { | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1290 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); | 
|  | 1291 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); | 
|  | 1292 | __ psrlq(src_reg, Immediate(32)); | 
|  | 1293 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1294 | } else { | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1295 | // No conflict possible, so just do the moves. | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1296 | DCHECK(source.IsDoubleStackSlot()); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1297 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); | 
|  | 1298 | __ movl(destination.AsRegisterPairHigh<Register>(), | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1299 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); | 
|  | 1300 | } | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1301 | } else if (destination.IsFpuRegister()) { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 1302 | if (source.IsFpuRegister()) { | 
|  | 1303 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
|  | 1304 | } else if (source.IsDoubleStackSlot()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1305 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1306 | } else if (source.IsRegisterPair()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1307 | size_t elem_size = DataType::Size(DataType::Type::kInt32); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1308 | // Create stack space for 2 elements. | 
|  | 1309 | __ subl(ESP, Immediate(2 * elem_size)); | 
|  | 1310 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); | 
|  | 1311 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); | 
|  | 1312 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); | 
|  | 1313 | // And remove the temporary stack space we allocated. | 
|  | 1314 | __ addl(ESP, Immediate(2 * elem_size)); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1315 | } else { | 
|  | 1316 | LOG(FATAL) << "Unimplemented"; | 
|  | 1317 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1318 | } else { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1319 | DCHECK(destination.IsDoubleStackSlot()) << destination; | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1320 | if (source.IsRegisterPair()) { | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1321 | // No conflict possible, so just do the moves. | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1322 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1323 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 1324 | source.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 1325 | } else if (source.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 1326 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1327 | } else if (source.IsConstant()) { | 
|  | 1328 | HConstant* constant = source.GetConstant(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1329 | DCHECK(constant->IsLongConstant() || constant->IsDoubleConstant()); | 
|  | 1330 | int64_t value = GetInt64ValueOf(constant); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1331 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(Low32Bits(value))); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1332 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), | 
|  | 1333 | Immediate(High32Bits(value))); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1334 | } else { | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 1335 | DCHECK(source.IsDoubleStackSlot()) << source; | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1336 | EmitParallelMoves( | 
|  | 1337 | Location::StackSlot(source.GetStackIndex()), | 
|  | 1338 | Location::StackSlot(destination.GetStackIndex()), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1339 | DataType::Type::kInt32, | 
| Nicolas Geoffray | 32b2a52 | 2014-11-27 14:54:18 +0000 | [diff] [blame] | 1340 | Location::StackSlot(source.GetHighStackIndex(kX86WordSize)), | 
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 1341 | Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1342 | DataType::Type::kInt32); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1343 | } | 
|  | 1344 | } | 
|  | 1345 | } | 
|  | 1346 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1347 | void CodeGeneratorX86::MoveConstant(Location location, int32_t value) { | 
|  | 1348 | DCHECK(location.IsRegister()); | 
|  | 1349 | __ movl(location.AsRegister<Register>(), Immediate(value)); | 
|  | 1350 | } | 
|  | 1351 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1352 | void CodeGeneratorX86::MoveLocation(Location dst, Location src, DataType::Type dst_type) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1353 | HParallelMove move(GetGraph()->GetAllocator()); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1354 | if (dst_type == DataType::Type::kInt64 && !src.IsConstant() && !src.IsFpuRegister()) { | 
|  | 1355 | move.AddMove(src.ToLow(), dst.ToLow(), DataType::Type::kInt32, nullptr); | 
|  | 1356 | move.AddMove(src.ToHigh(), dst.ToHigh(), DataType::Type::kInt32, nullptr); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1357 | } else { | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1358 | move.AddMove(src, dst, dst_type, nullptr); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1359 | } | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1360 | GetMoveResolver()->EmitNativeCode(&move); | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1361 | } | 
|  | 1362 |  | 
|  | 1363 | void CodeGeneratorX86::AddLocationAsTemp(Location location, LocationSummary* locations) { | 
|  | 1364 | if (location.IsRegister()) { | 
|  | 1365 | locations->AddTemp(location); | 
|  | 1366 | } else if (location.IsRegisterPair()) { | 
|  | 1367 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>())); | 
|  | 1368 | locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>())); | 
|  | 1369 | } else { | 
|  | 1370 | UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location; | 
|  | 1371 | } | 
|  | 1372 | } | 
|  | 1373 |  | 
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1374 | void InstructionCodeGeneratorX86::HandleGoto(HInstruction* got, HBasicBlock* successor) { | 
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 1375 | if (successor->IsExitBlock()) { | 
|  | 1376 | DCHECK(got->GetPrevious()->AlwaysThrows()); | 
|  | 1377 | return;  // no code needed | 
|  | 1378 | } | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1379 |  | 
|  | 1380 | HBasicBlock* block = got->GetBlock(); | 
|  | 1381 | HInstruction* previous = got->GetPrevious(); | 
|  | 1382 |  | 
|  | 1383 | HLoopInformation* info = block->GetLoopInformation(); | 
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1384 | if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) { | 
| Nicolas Geoffray | 8d72832 | 2018-01-18 22:44:32 +0000 | [diff] [blame] | 1385 | if (codegen_->GetCompilerOptions().CountHotnessInCompiledCode()) { | 
|  | 1386 | __ pushl(EAX); | 
|  | 1387 | __ movl(EAX, Address(ESP, kX86WordSize)); | 
|  | 1388 | __ addw(Address(EAX, ArtMethod::HotnessCountOffset().Int32Value()), Immediate(1)); | 
|  | 1389 | __ popl(EAX); | 
|  | 1390 | } | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1391 | GenerateSuspendCheck(info->GetSuspendCheck(), successor); | 
|  | 1392 | return; | 
|  | 1393 | } | 
|  | 1394 |  | 
|  | 1395 | if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) { | 
|  | 1396 | GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr); | 
|  | 1397 | } | 
|  | 1398 | if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) { | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1399 | __ jmp(codegen_->GetLabelOf(successor)); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1400 | } | 
|  | 1401 | } | 
|  | 1402 |  | 
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1403 | void LocationsBuilderX86::VisitGoto(HGoto* got) { | 
|  | 1404 | got->SetLocations(nullptr); | 
|  | 1405 | } | 
|  | 1406 |  | 
|  | 1407 | void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) { | 
|  | 1408 | HandleGoto(got, got->GetSuccessor()); | 
|  | 1409 | } | 
|  | 1410 |  | 
|  | 1411 | void LocationsBuilderX86::VisitTryBoundary(HTryBoundary* try_boundary) { | 
|  | 1412 | try_boundary->SetLocations(nullptr); | 
|  | 1413 | } | 
|  | 1414 |  | 
|  | 1415 | void InstructionCodeGeneratorX86::VisitTryBoundary(HTryBoundary* try_boundary) { | 
|  | 1416 | HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor(); | 
|  | 1417 | if (!successor->IsExitBlock()) { | 
|  | 1418 | HandleGoto(try_boundary, successor); | 
|  | 1419 | } | 
|  | 1420 | } | 
|  | 1421 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1422 | void LocationsBuilderX86::VisitExit(HExit* exit) { | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1423 | exit->SetLocations(nullptr); | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1424 | } | 
|  | 1425 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1426 | void InstructionCodeGeneratorX86::VisitExit(HExit* exit ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1427 | } | 
|  | 1428 |  | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1429 | template<class LabelType> | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1430 | void InstructionCodeGeneratorX86::GenerateFPJumps(HCondition* cond, | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1431 | LabelType* true_label, | 
|  | 1432 | LabelType* false_label) { | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1433 | if (cond->IsFPConditionTrueIfNaN()) { | 
|  | 1434 | __ j(kUnordered, true_label); | 
|  | 1435 | } else if (cond->IsFPConditionFalseIfNaN()) { | 
|  | 1436 | __ j(kUnordered, false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1437 | } | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1438 | __ j(X86UnsignedOrFPCondition(cond->GetCondition()), true_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1439 | } | 
|  | 1440 |  | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1441 | template<class LabelType> | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1442 | void InstructionCodeGeneratorX86::GenerateLongComparesAndJumps(HCondition* cond, | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1443 | LabelType* true_label, | 
|  | 1444 | LabelType* false_label) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1445 | LocationSummary* locations = cond->GetLocations(); | 
|  | 1446 | Location left = locations->InAt(0); | 
|  | 1447 | Location right = locations->InAt(1); | 
|  | 1448 | IfCondition if_cond = cond->GetCondition(); | 
|  | 1449 |  | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1450 | Register left_high = left.AsRegisterPairHigh<Register>(); | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1451 | Register left_low = left.AsRegisterPairLow<Register>(); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1452 | IfCondition true_high_cond = if_cond; | 
|  | 1453 | IfCondition false_high_cond = cond->GetOppositeCondition(); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1454 | Condition final_condition = X86UnsignedOrFPCondition(if_cond);  // unsigned on lower part | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1455 |  | 
|  | 1456 | // Set the conditions for the test, remembering that == needs to be | 
|  | 1457 | // decided using the low words. | 
|  | 1458 | switch (if_cond) { | 
|  | 1459 | case kCondEQ: | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1460 | case kCondNE: | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1461 | // Nothing to do. | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1462 | break; | 
|  | 1463 | case kCondLT: | 
|  | 1464 | false_high_cond = kCondGT; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1465 | break; | 
|  | 1466 | case kCondLE: | 
|  | 1467 | true_high_cond = kCondLT; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1468 | break; | 
|  | 1469 | case kCondGT: | 
|  | 1470 | false_high_cond = kCondLT; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1471 | break; | 
|  | 1472 | case kCondGE: | 
|  | 1473 | true_high_cond = kCondGT; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1474 | break; | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1475 | case kCondB: | 
|  | 1476 | false_high_cond = kCondA; | 
|  | 1477 | break; | 
|  | 1478 | case kCondBE: | 
|  | 1479 | true_high_cond = kCondB; | 
|  | 1480 | break; | 
|  | 1481 | case kCondA: | 
|  | 1482 | false_high_cond = kCondB; | 
|  | 1483 | break; | 
|  | 1484 | case kCondAE: | 
|  | 1485 | true_high_cond = kCondA; | 
|  | 1486 | break; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1487 | } | 
|  | 1488 |  | 
|  | 1489 | if (right.IsConstant()) { | 
|  | 1490 | int64_t value = right.GetConstant()->AsLongConstant()->GetValue(); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1491 | int32_t val_high = High32Bits(value); | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1492 | int32_t val_low = Low32Bits(value); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1493 |  | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1494 | codegen_->Compare32BitValue(left_high, val_high); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1495 | if (if_cond == kCondNE) { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1496 | __ j(X86Condition(true_high_cond), true_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1497 | } else if (if_cond == kCondEQ) { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1498 | __ j(X86Condition(false_high_cond), false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1499 | } else { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1500 | __ j(X86Condition(true_high_cond), true_label); | 
|  | 1501 | __ j(X86Condition(false_high_cond), false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1502 | } | 
|  | 1503 | // Must be equal high, so compare the lows. | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 1504 | codegen_->Compare32BitValue(left_low, val_low); | 
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1505 | } else if (right.IsRegisterPair()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1506 | Register right_high = right.AsRegisterPairHigh<Register>(); | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1507 | Register right_low = right.AsRegisterPairLow<Register>(); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1508 |  | 
|  | 1509 | __ cmpl(left_high, right_high); | 
|  | 1510 | if (if_cond == kCondNE) { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1511 | __ j(X86Condition(true_high_cond), true_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1512 | } else if (if_cond == kCondEQ) { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1513 | __ j(X86Condition(false_high_cond), false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1514 | } else { | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1515 | __ j(X86Condition(true_high_cond), true_label); | 
|  | 1516 | __ j(X86Condition(false_high_cond), false_label); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1517 | } | 
|  | 1518 | // Must be equal high, so compare the lows. | 
|  | 1519 | __ cmpl(left_low, right_low); | 
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1520 | } else { | 
|  | 1521 | DCHECK(right.IsDoubleStackSlot()); | 
|  | 1522 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); | 
|  | 1523 | if (if_cond == kCondNE) { | 
|  | 1524 | __ j(X86Condition(true_high_cond), true_label); | 
|  | 1525 | } else if (if_cond == kCondEQ) { | 
|  | 1526 | __ j(X86Condition(false_high_cond), false_label); | 
|  | 1527 | } else { | 
|  | 1528 | __ j(X86Condition(true_high_cond), true_label); | 
|  | 1529 | __ j(X86Condition(false_high_cond), false_label); | 
|  | 1530 | } | 
|  | 1531 | // Must be equal high, so compare the lows. | 
|  | 1532 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1533 | } | 
|  | 1534 | // The last comparison might be unsigned. | 
|  | 1535 | __ j(final_condition, true_label); | 
|  | 1536 | } | 
|  | 1537 |  | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1538 | void InstructionCodeGeneratorX86::GenerateFPCompare(Location lhs, | 
|  | 1539 | Location rhs, | 
|  | 1540 | HInstruction* insn, | 
|  | 1541 | bool is_double) { | 
|  | 1542 | HX86LoadFromConstantTable* const_area = insn->InputAt(1)->AsX86LoadFromConstantTable(); | 
|  | 1543 | if (is_double) { | 
|  | 1544 | if (rhs.IsFpuRegister()) { | 
|  | 1545 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); | 
|  | 1546 | } else if (const_area != nullptr) { | 
|  | 1547 | DCHECK(const_area->IsEmittedAtUseSite()); | 
|  | 1548 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), | 
|  | 1549 | codegen_->LiteralDoubleAddress( | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1550 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
|  | 1551 | const_area->GetBaseMethodAddress(), | 
|  | 1552 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1553 | } else { | 
|  | 1554 | DCHECK(rhs.IsDoubleStackSlot()); | 
|  | 1555 | __ ucomisd(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); | 
|  | 1556 | } | 
|  | 1557 | } else { | 
|  | 1558 | if (rhs.IsFpuRegister()) { | 
|  | 1559 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), rhs.AsFpuRegister<XmmRegister>()); | 
|  | 1560 | } else if (const_area != nullptr) { | 
|  | 1561 | DCHECK(const_area->IsEmittedAtUseSite()); | 
|  | 1562 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), | 
|  | 1563 | codegen_->LiteralFloatAddress( | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 1564 | const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
|  | 1565 | const_area->GetBaseMethodAddress(), | 
|  | 1566 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1567 | } else { | 
|  | 1568 | DCHECK(rhs.IsStackSlot()); | 
|  | 1569 | __ ucomiss(lhs.AsFpuRegister<XmmRegister>(), Address(ESP, rhs.GetStackIndex())); | 
|  | 1570 | } | 
|  | 1571 | } | 
|  | 1572 | } | 
|  | 1573 |  | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1574 | template<class LabelType> | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1575 | void InstructionCodeGeneratorX86::GenerateCompareTestAndBranch(HCondition* condition, | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1576 | LabelType* true_target_in, | 
|  | 1577 | LabelType* false_target_in) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1578 | // Generated branching requires both targets to be explicit. If either of the | 
|  | 1579 | // targets is nullptr (fallthrough) use and bind `fallthrough_target` instead. | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1580 | LabelType fallthrough_target; | 
|  | 1581 | LabelType* true_target = true_target_in == nullptr ? &fallthrough_target : true_target_in; | 
|  | 1582 | LabelType* false_target = false_target_in == nullptr ? &fallthrough_target : false_target_in; | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1583 |  | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1584 | LocationSummary* locations = condition->GetLocations(); | 
|  | 1585 | Location left = locations->InAt(0); | 
|  | 1586 | Location right = locations->InAt(1); | 
|  | 1587 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1588 | DataType::Type type = condition->InputAt(0)->GetType(); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1589 | switch (type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1590 | case DataType::Type::kInt64: | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1591 | GenerateLongComparesAndJumps(condition, true_target, false_target); | 
|  | 1592 | break; | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1593 | case DataType::Type::kFloat32: | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1594 | GenerateFPCompare(left, right, condition, false); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1595 | GenerateFPJumps(condition, true_target, false_target); | 
|  | 1596 | break; | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1597 | case DataType::Type::kFloat64: | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1598 | GenerateFPCompare(left, right, condition, true); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1599 | GenerateFPJumps(condition, true_target, false_target); | 
|  | 1600 | break; | 
|  | 1601 | default: | 
|  | 1602 | LOG(FATAL) << "Unexpected compare type " << type; | 
|  | 1603 | } | 
|  | 1604 |  | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1605 | if (false_target != &fallthrough_target) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1606 | __ jmp(false_target); | 
|  | 1607 | } | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1608 |  | 
|  | 1609 | if (fallthrough_target.IsLinked()) { | 
|  | 1610 | __ Bind(&fallthrough_target); | 
|  | 1611 | } | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1612 | } | 
|  | 1613 |  | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1614 | static bool AreEflagsSetFrom(HInstruction* cond, HInstruction* branch) { | 
|  | 1615 | // Moves may affect the eflags register (move zero uses xorl), so the EFLAGS | 
|  | 1616 | // are set only strictly before `branch`. We can't use the eflags on long/FP | 
|  | 1617 | // conditions if they are materialized due to the complex branching. | 
|  | 1618 | return cond->IsCondition() && | 
|  | 1619 | cond->GetNext() == branch && | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1620 | cond->InputAt(0)->GetType() != DataType::Type::kInt64 && | 
|  | 1621 | !DataType::IsFloatingPointType(cond->InputAt(0)->GetType()); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1622 | } | 
|  | 1623 |  | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1624 | template<class LabelType> | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1625 | void InstructionCodeGeneratorX86::GenerateTestAndBranch(HInstruction* instruction, | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1626 | size_t condition_input_index, | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1627 | LabelType* true_target, | 
|  | 1628 | LabelType* false_target) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1629 | HInstruction* cond = instruction->InputAt(condition_input_index); | 
|  | 1630 |  | 
|  | 1631 | if (true_target == nullptr && false_target == nullptr) { | 
|  | 1632 | // Nothing to do. The code always falls through. | 
|  | 1633 | return; | 
|  | 1634 | } else if (cond->IsIntConstant()) { | 
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1635 | // Constant condition, statically compared against "true" (integer value 1). | 
|  | 1636 | if (cond->AsIntConstant()->IsTrue()) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1637 | if (true_target != nullptr) { | 
|  | 1638 | __ jmp(true_target); | 
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1639 | } | 
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1640 | } else { | 
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 1641 | DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue(); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1642 | if (false_target != nullptr) { | 
|  | 1643 | __ jmp(false_target); | 
|  | 1644 | } | 
|  | 1645 | } | 
|  | 1646 | return; | 
|  | 1647 | } | 
|  | 1648 |  | 
|  | 1649 | // The following code generates these patterns: | 
|  | 1650 | //  (1) true_target == nullptr && false_target != nullptr | 
|  | 1651 | //        - opposite condition true => branch to false_target | 
|  | 1652 | //  (2) true_target != nullptr && false_target == nullptr | 
|  | 1653 | //        - condition true => branch to true_target | 
|  | 1654 | //  (3) true_target != nullptr && false_target != nullptr | 
|  | 1655 | //        - condition true => branch to true_target | 
|  | 1656 | //        - branch to false_target | 
|  | 1657 | if (IsBooleanValueOrMaterializedCondition(cond)) { | 
|  | 1658 | if (AreEflagsSetFrom(cond, instruction)) { | 
|  | 1659 | if (true_target == nullptr) { | 
|  | 1660 | __ j(X86Condition(cond->AsCondition()->GetOppositeCondition()), false_target); | 
|  | 1661 | } else { | 
|  | 1662 | __ j(X86Condition(cond->AsCondition()->GetCondition()), true_target); | 
|  | 1663 | } | 
|  | 1664 | } else { | 
|  | 1665 | // Materialized condition, compare against 0. | 
|  | 1666 | Location lhs = instruction->GetLocations()->InAt(condition_input_index); | 
|  | 1667 | if (lhs.IsRegister()) { | 
|  | 1668 | __ testl(lhs.AsRegister<Register>(), lhs.AsRegister<Register>()); | 
|  | 1669 | } else { | 
|  | 1670 | __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0)); | 
|  | 1671 | } | 
|  | 1672 | if (true_target == nullptr) { | 
|  | 1673 | __ j(kEqual, false_target); | 
|  | 1674 | } else { | 
|  | 1675 | __ j(kNotEqual, true_target); | 
|  | 1676 | } | 
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 1677 | } | 
|  | 1678 | } else { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1679 | // Condition has not been materialized, use its inputs as the comparison and | 
|  | 1680 | // its condition as the branch condition. | 
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1681 | HCondition* condition = cond->AsCondition(); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1682 |  | 
|  | 1683 | // If this is a long or FP comparison that has been folded into | 
|  | 1684 | // the HCondition, generate the comparison directly. | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1685 | DataType::Type type = condition->InputAt(0)->GetType(); | 
|  | 1686 | if (type == DataType::Type::kInt64 || DataType::IsFloatingPointType(type)) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1687 | GenerateCompareTestAndBranch(condition, true_target, false_target); | 
|  | 1688 | return; | 
|  | 1689 | } | 
|  | 1690 |  | 
|  | 1691 | Location lhs = condition->GetLocations()->InAt(0); | 
|  | 1692 | Location rhs = condition->GetLocations()->InAt(1); | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1693 | // LHS is guaranteed to be in a register (see LocationsBuilderX86::HandleCondition). | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 1694 | codegen_->GenerateIntCompare(lhs, rhs); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1695 | if (true_target == nullptr) { | 
|  | 1696 | __ j(X86Condition(condition->GetOppositeCondition()), false_target); | 
|  | 1697 | } else { | 
| Mark Mendell | b8b9769 | 2015-05-22 16:58:19 -0400 | [diff] [blame] | 1698 | __ j(X86Condition(condition->GetCondition()), true_target); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1699 | } | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1700 | } | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1701 |  | 
|  | 1702 | // If neither branch falls through (case 3), the conditional branch to `true_target` | 
|  | 1703 | // was already emitted (case 2) and we need to emit a jump to `false_target`. | 
|  | 1704 | if (true_target != nullptr && false_target != nullptr) { | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1705 | __ jmp(false_target); | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1706 | } | 
|  | 1707 | } | 
|  | 1708 |  | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1709 | void LocationsBuilderX86::VisitIf(HIf* if_instr) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1710 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(if_instr); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1711 | if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) { | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1712 | locations->SetInAt(0, Location::Any()); | 
|  | 1713 | } | 
|  | 1714 | } | 
|  | 1715 |  | 
|  | 1716 | void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) { | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1717 | HBasicBlock* true_successor = if_instr->IfTrueSuccessor(); | 
|  | 1718 | HBasicBlock* false_successor = if_instr->IfFalseSuccessor(); | 
|  | 1719 | Label* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ? | 
|  | 1720 | nullptr : codegen_->GetLabelOf(true_successor); | 
|  | 1721 | Label* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ? | 
|  | 1722 | nullptr : codegen_->GetLabelOf(false_successor); | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1723 | GenerateTestAndBranch(if_instr, /* condition_input_index= */ 0, true_target, false_target); | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1724 | } | 
|  | 1725 |  | 
|  | 1726 | void LocationsBuilderX86::VisitDeoptimize(HDeoptimize* deoptimize) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1727 | LocationSummary* locations = new (GetGraph()->GetAllocator()) | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1728 | LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath); | 
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 1729 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 1730 | RegisterSet caller_saves = RegisterSet::Empty(); | 
|  | 1731 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 1732 | locations->SetCustomSlowPathCallerSaves(caller_saves); | 
| David Brazdil | 0debae7 | 2015-11-12 18:37:00 +0000 | [diff] [blame] | 1733 | if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) { | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1734 | locations->SetInAt(0, Location::Any()); | 
|  | 1735 | } | 
|  | 1736 | } | 
|  | 1737 |  | 
|  | 1738 | void InstructionCodeGeneratorX86::VisitDeoptimize(HDeoptimize* deoptimize) { | 
| Aart Bik | 42249c3 | 2016-01-07 15:33:50 -0800 | [diff] [blame] | 1739 | SlowPathCode* slow_path = deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathX86>(deoptimize); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1740 | GenerateTestAndBranch<Label>(deoptimize, | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1741 | /* condition_input_index= */ 0, | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1742 | slow_path->GetEntryLabel(), | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1743 | /* false_target= */ nullptr); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1744 | } | 
|  | 1745 |  | 
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1746 | void LocationsBuilderX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1747 | LocationSummary* locations = new (GetGraph()->GetAllocator()) | 
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1748 | LocationSummary(flag, LocationSummary::kNoCall); | 
|  | 1749 | locations->SetOut(Location::RequiresRegister()); | 
|  | 1750 | } | 
|  | 1751 |  | 
|  | 1752 | void InstructionCodeGeneratorX86::VisitShouldDeoptimizeFlag(HShouldDeoptimizeFlag* flag) { | 
|  | 1753 | __ movl(flag->GetLocations()->Out().AsRegister<Register>(), | 
|  | 1754 | Address(ESP, codegen_->GetStackOffsetOfShouldDeoptimizeFlag())); | 
|  | 1755 | } | 
|  | 1756 |  | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1757 | static bool SelectCanUseCMOV(HSelect* select) { | 
|  | 1758 | // There are no conditional move instructions for XMMs. | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1759 | if (DataType::IsFloatingPointType(select->GetType())) { | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1760 | return false; | 
|  | 1761 | } | 
|  | 1762 |  | 
|  | 1763 | // A FP condition doesn't generate the single CC that we need. | 
|  | 1764 | // In 32 bit mode, a long condition doesn't generate a single CC either. | 
|  | 1765 | HInstruction* condition = select->GetCondition(); | 
|  | 1766 | if (condition->IsCondition()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1767 | DataType::Type compare_type = condition->InputAt(0)->GetType(); | 
|  | 1768 | if (compare_type == DataType::Type::kInt64 || | 
|  | 1769 | DataType::IsFloatingPointType(compare_type)) { | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1770 | return false; | 
|  | 1771 | } | 
|  | 1772 | } | 
|  | 1773 |  | 
|  | 1774 | // We can generate a CMOV for this Select. | 
|  | 1775 | return true; | 
|  | 1776 | } | 
|  | 1777 |  | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1778 | void LocationsBuilderX86::VisitSelect(HSelect* select) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1779 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(select); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1780 | if (DataType::IsFloatingPointType(select->GetType())) { | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1781 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1782 | locations->SetInAt(1, Location::Any()); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1783 | } else { | 
|  | 1784 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1785 | if (SelectCanUseCMOV(select)) { | 
|  | 1786 | if (select->InputAt(1)->IsConstant()) { | 
|  | 1787 | // Cmov can't handle a constant value. | 
|  | 1788 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 1789 | } else { | 
|  | 1790 | locations->SetInAt(1, Location::Any()); | 
|  | 1791 | } | 
|  | 1792 | } else { | 
|  | 1793 | locations->SetInAt(1, Location::Any()); | 
|  | 1794 | } | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1795 | } | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1796 | if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) { | 
|  | 1797 | locations->SetInAt(2, Location::RequiresRegister()); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1798 | } | 
|  | 1799 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 1800 | } | 
|  | 1801 |  | 
|  | 1802 | void InstructionCodeGeneratorX86::VisitSelect(HSelect* select) { | 
|  | 1803 | LocationSummary* locations = select->GetLocations(); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1804 | DCHECK(locations->InAt(0).Equals(locations->Out())); | 
|  | 1805 | if (SelectCanUseCMOV(select)) { | 
|  | 1806 | // If both the condition and the source types are integer, we can generate | 
|  | 1807 | // a CMOV to implement Select. | 
|  | 1808 |  | 
|  | 1809 | HInstruction* select_condition = select->GetCondition(); | 
|  | 1810 | Condition cond = kNotEqual; | 
|  | 1811 |  | 
|  | 1812 | // Figure out how to test the 'condition'. | 
|  | 1813 | if (select_condition->IsCondition()) { | 
|  | 1814 | HCondition* condition = select_condition->AsCondition(); | 
|  | 1815 | if (!condition->IsEmittedAtUseSite()) { | 
|  | 1816 | // This was a previously materialized condition. | 
|  | 1817 | // Can we use the existing condition code? | 
|  | 1818 | if (AreEflagsSetFrom(condition, select)) { | 
|  | 1819 | // Materialization was the previous instruction. Condition codes are right. | 
|  | 1820 | cond = X86Condition(condition->GetCondition()); | 
|  | 1821 | } else { | 
|  | 1822 | // No, we have to recreate the condition code. | 
|  | 1823 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); | 
|  | 1824 | __ testl(cond_reg, cond_reg); | 
|  | 1825 | } | 
|  | 1826 | } else { | 
|  | 1827 | // We can't handle FP or long here. | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1828 | DCHECK_NE(condition->InputAt(0)->GetType(), DataType::Type::kInt64); | 
|  | 1829 | DCHECK(!DataType::IsFloatingPointType(condition->InputAt(0)->GetType())); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1830 | LocationSummary* cond_locations = condition->GetLocations(); | 
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1831 | codegen_->GenerateIntCompare(cond_locations->InAt(0), cond_locations->InAt(1)); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1832 | cond = X86Condition(condition->GetCondition()); | 
|  | 1833 | } | 
|  | 1834 | } else { | 
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 1835 | // Must be a Boolean condition, which needs to be compared to 0. | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1836 | Register cond_reg = locations->InAt(2).AsRegister<Register>(); | 
|  | 1837 | __ testl(cond_reg, cond_reg); | 
|  | 1838 | } | 
|  | 1839 |  | 
|  | 1840 | // If the condition is true, overwrite the output, which already contains false. | 
|  | 1841 | Location false_loc = locations->InAt(0); | 
|  | 1842 | Location true_loc = locations->InAt(1); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1843 | if (select->GetType() == DataType::Type::kInt64) { | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1844 | // 64 bit conditional move. | 
|  | 1845 | Register false_high = false_loc.AsRegisterPairHigh<Register>(); | 
|  | 1846 | Register false_low = false_loc.AsRegisterPairLow<Register>(); | 
|  | 1847 | if (true_loc.IsRegisterPair()) { | 
|  | 1848 | __ cmovl(cond, false_high, true_loc.AsRegisterPairHigh<Register>()); | 
|  | 1849 | __ cmovl(cond, false_low, true_loc.AsRegisterPairLow<Register>()); | 
|  | 1850 | } else { | 
|  | 1851 | __ cmovl(cond, false_high, Address(ESP, true_loc.GetHighStackIndex(kX86WordSize))); | 
|  | 1852 | __ cmovl(cond, false_low, Address(ESP, true_loc.GetStackIndex())); | 
|  | 1853 | } | 
|  | 1854 | } else { | 
|  | 1855 | // 32 bit conditional move. | 
|  | 1856 | Register false_reg = false_loc.AsRegister<Register>(); | 
|  | 1857 | if (true_loc.IsRegister()) { | 
|  | 1858 | __ cmovl(cond, false_reg, true_loc.AsRegister<Register>()); | 
|  | 1859 | } else { | 
|  | 1860 | __ cmovl(cond, false_reg, Address(ESP, true_loc.GetStackIndex())); | 
|  | 1861 | } | 
|  | 1862 | } | 
|  | 1863 | } else { | 
|  | 1864 | NearLabel false_target; | 
|  | 1865 | GenerateTestAndBranch<NearLabel>( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1866 | select, /* condition_input_index= */ 2, /* true_target= */ nullptr, &false_target); | 
| Mark Mendell | 0c5b18e | 2016-02-06 13:58:35 -0500 | [diff] [blame] | 1867 | codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType()); | 
|  | 1868 | __ Bind(&false_target); | 
|  | 1869 | } | 
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1870 | } | 
|  | 1871 |  | 
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1872 | void LocationsBuilderX86::VisitNativeDebugInfo(HNativeDebugInfo* info) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1873 | new (GetGraph()->GetAllocator()) LocationSummary(info); | 
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1874 | } | 
|  | 1875 |  | 
| David Srbecky | d28f4a0 | 2016-03-14 17:14:24 +0000 | [diff] [blame] | 1876 | void InstructionCodeGeneratorX86::VisitNativeDebugInfo(HNativeDebugInfo*) { | 
|  | 1877 | // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile. | 
| David Srbecky | c7098ff | 2016-02-09 14:30:11 +0000 | [diff] [blame] | 1878 | } | 
|  | 1879 |  | 
|  | 1880 | void CodeGeneratorX86::GenerateNop() { | 
|  | 1881 | __ nop(); | 
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1882 | } | 
|  | 1883 |  | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1884 | void LocationsBuilderX86::HandleCondition(HCondition* cond) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1885 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1886 | new (GetGraph()->GetAllocator()) LocationSummary(cond, LocationSummary::kNoCall); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1887 | // Handle the long/FP comparisons made in instruction simplification. | 
|  | 1888 | switch (cond->InputAt(0)->GetType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1889 | case DataType::Type::kInt64: { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1890 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Mark Mendell | 8659e84 | 2016-02-16 10:41:46 -0500 | [diff] [blame] | 1891 | locations->SetInAt(1, Location::Any()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1892 | if (!cond->IsEmittedAtUseSite()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1893 | locations->SetOut(Location::RequiresRegister()); | 
|  | 1894 | } | 
|  | 1895 | break; | 
|  | 1896 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1897 | case DataType::Type::kFloat32: | 
|  | 1898 | case DataType::Type::kFloat64: { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1899 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1900 | if (cond->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 1901 | DCHECK(cond->InputAt(1)->IsEmittedAtUseSite()); | 
|  | 1902 | } else if (cond->InputAt(1)->IsConstant()) { | 
|  | 1903 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 1904 | } else { | 
|  | 1905 | locations->SetInAt(1, Location::Any()); | 
|  | 1906 | } | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1907 | if (!cond->IsEmittedAtUseSite()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1908 | locations->SetOut(Location::RequiresRegister()); | 
|  | 1909 | } | 
|  | 1910 | break; | 
|  | 1911 | } | 
|  | 1912 | default: | 
|  | 1913 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 1914 | locations->SetInAt(1, Location::Any()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1915 | if (!cond->IsEmittedAtUseSite()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1916 | // We need a byte register. | 
|  | 1917 | locations->SetOut(Location::RegisterLocation(ECX)); | 
|  | 1918 | } | 
|  | 1919 | break; | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 1920 | } | 
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1921 | } | 
|  | 1922 |  | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1923 | void InstructionCodeGeneratorX86::HandleCondition(HCondition* cond) { | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 1924 | if (cond->IsEmittedAtUseSite()) { | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1925 | return; | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 1926 | } | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1927 |  | 
|  | 1928 | LocationSummary* locations = cond->GetLocations(); | 
|  | 1929 | Location lhs = locations->InAt(0); | 
|  | 1930 | Location rhs = locations->InAt(1); | 
|  | 1931 | Register reg = locations->Out().AsRegister<Register>(); | 
| Mark Mendell | 152408f | 2015-12-31 12:28:50 -0500 | [diff] [blame] | 1932 | NearLabel true_label, false_label; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1933 |  | 
|  | 1934 | switch (cond->InputAt(0)->GetType()) { | 
|  | 1935 | default: { | 
|  | 1936 | // Integer case. | 
|  | 1937 |  | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 1938 | // Clear output register: setb only sets the low byte. | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1939 | __ xorl(reg, reg); | 
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1940 | codegen_->GenerateIntCompare(lhs, rhs); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1941 | __ setb(X86Condition(cond->GetCondition()), reg); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1942 | return; | 
|  | 1943 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1944 | case DataType::Type::kInt64: | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1945 | GenerateLongComparesAndJumps(cond, &true_label, &false_label); | 
|  | 1946 | break; | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1947 | case DataType::Type::kFloat32: | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1948 | GenerateFPCompare(lhs, rhs, cond, false); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1949 | GenerateFPJumps(cond, &true_label, &false_label); | 
|  | 1950 | break; | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1951 | case DataType::Type::kFloat64: | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1952 | GenerateFPCompare(lhs, rhs, cond, true); | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1953 | GenerateFPJumps(cond, &true_label, &false_label); | 
|  | 1954 | break; | 
|  | 1955 | } | 
|  | 1956 |  | 
|  | 1957 | // Convert the jumps into the result. | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1958 | NearLabel done_label; | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1959 |  | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1960 | // False case: result = 0. | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1961 | __ Bind(&false_label); | 
|  | 1962 | __ xorl(reg, reg); | 
|  | 1963 | __ jmp(&done_label); | 
|  | 1964 |  | 
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 1965 | // True case: result = 1. | 
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1966 | __ Bind(&true_label); | 
|  | 1967 | __ movl(reg, Immediate(1)); | 
|  | 1968 | __ Bind(&done_label); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1969 | } | 
|  | 1970 |  | 
|  | 1971 | void LocationsBuilderX86::VisitEqual(HEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1972 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1973 | } | 
|  | 1974 |  | 
|  | 1975 | void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1976 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1977 | } | 
|  | 1978 |  | 
|  | 1979 | void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1980 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1981 | } | 
|  | 1982 |  | 
|  | 1983 | void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1984 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1985 | } | 
|  | 1986 |  | 
|  | 1987 | void LocationsBuilderX86::VisitLessThan(HLessThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1988 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1989 | } | 
|  | 1990 |  | 
|  | 1991 | void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1992 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1993 | } | 
|  | 1994 |  | 
|  | 1995 | void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1996 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1997 | } | 
|  | 1998 |  | 
|  | 1999 | void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2000 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2001 | } | 
|  | 2002 |  | 
|  | 2003 | void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2004 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2005 | } | 
|  | 2006 |  | 
|  | 2007 | void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2008 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2009 | } | 
|  | 2010 |  | 
|  | 2011 | void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2012 | HandleCondition(comp); | 
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2013 | } | 
|  | 2014 |  | 
|  | 2015 | void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2016 | HandleCondition(comp); | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2017 | } | 
|  | 2018 |  | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2019 | void LocationsBuilderX86::VisitBelow(HBelow* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2020 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2021 | } | 
|  | 2022 |  | 
|  | 2023 | void InstructionCodeGeneratorX86::VisitBelow(HBelow* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2024 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2025 | } | 
|  | 2026 |  | 
|  | 2027 | void LocationsBuilderX86::VisitBelowOrEqual(HBelowOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2028 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2029 | } | 
|  | 2030 |  | 
|  | 2031 | void InstructionCodeGeneratorX86::VisitBelowOrEqual(HBelowOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2032 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2033 | } | 
|  | 2034 |  | 
|  | 2035 | void LocationsBuilderX86::VisitAbove(HAbove* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2036 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2037 | } | 
|  | 2038 |  | 
|  | 2039 | void InstructionCodeGeneratorX86::VisitAbove(HAbove* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2040 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2041 | } | 
|  | 2042 |  | 
|  | 2043 | void LocationsBuilderX86::VisitAboveOrEqual(HAboveOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2044 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2045 | } | 
|  | 2046 |  | 
|  | 2047 | void InstructionCodeGeneratorX86::VisitAboveOrEqual(HAboveOrEqual* comp) { | 
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2048 | HandleCondition(comp); | 
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2049 | } | 
|  | 2050 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2051 | void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2052 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2053 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2054 | locations->SetOut(Location::ConstantLocation(constant)); | 
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2055 | } | 
|  | 2056 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2057 | void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) { | 
| Roland Levillain | 3a3fd0f | 2014-10-10 13:56:31 +0100 | [diff] [blame] | 2058 | // Will be generated at use site. | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2059 | } | 
|  | 2060 |  | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2061 | void LocationsBuilderX86::VisitNullConstant(HNullConstant* constant) { | 
|  | 2062 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2063 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2064 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2065 | } | 
|  | 2066 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2067 | void InstructionCodeGeneratorX86::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2068 | // Will be generated at use site. | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2069 | } | 
|  | 2070 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2071 | void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2072 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2073 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2074 | locations->SetOut(Location::ConstantLocation(constant)); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2075 | } | 
|  | 2076 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2077 | void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2078 | // Will be generated at use site. | 
|  | 2079 | } | 
|  | 2080 |  | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2081 | void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) { | 
|  | 2082 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2083 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2084 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2085 | } | 
|  | 2086 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2087 | void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2088 | // Will be generated at use site. | 
|  | 2089 | } | 
|  | 2090 |  | 
|  | 2091 | void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) { | 
|  | 2092 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2093 | new (GetGraph()->GetAllocator()) LocationSummary(constant, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2094 | locations->SetOut(Location::ConstantLocation(constant)); | 
|  | 2095 | } | 
|  | 2096 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2097 | void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2098 | // Will be generated at use site. | 
|  | 2099 | } | 
|  | 2100 |  | 
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2101 | void LocationsBuilderX86::VisitConstructorFence(HConstructorFence* constructor_fence) { | 
|  | 2102 | constructor_fence->SetLocations(nullptr); | 
|  | 2103 | } | 
|  | 2104 |  | 
|  | 2105 | void InstructionCodeGeneratorX86::VisitConstructorFence( | 
|  | 2106 | HConstructorFence* constructor_fence ATTRIBUTE_UNUSED) { | 
|  | 2107 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); | 
|  | 2108 | } | 
|  | 2109 |  | 
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2110 | void LocationsBuilderX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
|  | 2111 | memory_barrier->SetLocations(nullptr); | 
|  | 2112 | } | 
|  | 2113 |  | 
|  | 2114 | void InstructionCodeGeneratorX86::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 2115 | codegen_->GenerateMemoryBarrier(memory_barrier->GetBarrierKind()); | 
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 2116 | } | 
|  | 2117 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2118 | void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) { | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2119 | ret->SetLocations(nullptr); | 
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2120 | } | 
|  | 2121 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2122 | void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2123 | codegen_->GenerateFrameExit(); | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2124 | } | 
|  | 2125 |  | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2126 | void LocationsBuilderX86::VisitReturn(HReturn* ret) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2127 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2128 | new (GetGraph()->GetAllocator()) LocationSummary(ret, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2129 | switch (ret->InputAt(0)->GetType()) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2130 | case DataType::Type::kReference: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2131 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2132 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2133 | case DataType::Type::kInt8: | 
|  | 2134 | case DataType::Type::kUint16: | 
|  | 2135 | case DataType::Type::kInt16: | 
|  | 2136 | case DataType::Type::kInt32: | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2137 | locations->SetInAt(0, Location::RegisterLocation(EAX)); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2138 | break; | 
|  | 2139 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2140 | case DataType::Type::kInt64: | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2141 | locations->SetInAt( | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2142 | 0, Location::RegisterPairLocation(EAX, EDX)); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2143 | break; | 
|  | 2144 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2145 | case DataType::Type::kFloat32: | 
|  | 2146 | case DataType::Type::kFloat64: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2147 | locations->SetInAt( | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2148 | 0, Location::FpuRegisterLocation(XMM0)); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2149 | break; | 
|  | 2150 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2151 | default: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2152 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2153 | } | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2154 | } | 
|  | 2155 |  | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2156 | void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) { | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2157 | if (kIsDebugBuild) { | 
|  | 2158 | switch (ret->InputAt(0)->GetType()) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2159 | case DataType::Type::kReference: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2160 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2161 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2162 | case DataType::Type::kInt8: | 
|  | 2163 | case DataType::Type::kUint16: | 
|  | 2164 | case DataType::Type::kInt16: | 
|  | 2165 | case DataType::Type::kInt32: | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2166 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2167 | break; | 
|  | 2168 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2169 | case DataType::Type::kInt64: | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 2170 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX); | 
|  | 2171 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2172 | break; | 
|  | 2173 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2174 | case DataType::Type::kFloat32: | 
|  | 2175 | case DataType::Type::kFloat64: | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2176 | DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2177 | break; | 
|  | 2178 |  | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2179 | default: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2180 | LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType(); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2181 | } | 
|  | 2182 | } | 
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2183 | codegen_->GenerateFrameExit(); | 
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2184 | } | 
|  | 2185 |  | 
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 2186 | void LocationsBuilderX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
|  | 2187 | // The trampoline uses the same calling convention as dex calling conventions, | 
|  | 2188 | // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain | 
|  | 2189 | // the method_idx. | 
|  | 2190 | HandleInvoke(invoke); | 
|  | 2191 | } | 
|  | 2192 |  | 
|  | 2193 | void InstructionCodeGeneratorX86::VisitInvokeUnresolved(HInvokeUnresolved* invoke) { | 
|  | 2194 | codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke); | 
|  | 2195 | } | 
|  | 2196 |  | 
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2197 | void LocationsBuilderX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2198 | // Explicit clinit checks triggered by static invokes must have been pruned by | 
|  | 2199 | // art::PrepareForRegisterAllocation. | 
|  | 2200 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); | 
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2201 |  | 
| Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 2202 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2203 | if (intrinsic.TryDispatch(invoke)) { | 
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2204 | if (invoke->GetLocations()->CanCall() && | 
|  | 2205 | invoke->HasPcRelativeMethodLoadKind() && | 
|  | 2206 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).IsInvalid()) { | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 2207 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2208 | } | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2209 | return; | 
|  | 2210 | } | 
|  | 2211 |  | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2212 | HandleInvoke(invoke); | 
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2213 |  | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2214 | // For PC-relative dex cache the invoke has an extra input, the PC-relative address base. | 
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 2215 | if (invoke->HasPcRelativeMethodLoadKind()) { | 
| Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 2216 | invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 2217 | } | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2218 | } | 
|  | 2219 |  | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2220 | static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorX86* codegen) { | 
|  | 2221 | if (invoke->GetLocations()->Intrinsified()) { | 
|  | 2222 | IntrinsicCodeGeneratorX86 intrinsic(codegen); | 
|  | 2223 | intrinsic.Dispatch(invoke); | 
|  | 2224 | return true; | 
|  | 2225 | } | 
|  | 2226 | return false; | 
|  | 2227 | } | 
|  | 2228 |  | 
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2229 | void InstructionCodeGeneratorX86::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) { | 
| David Brazdil | 58282f4 | 2016-01-14 12:45:10 +0000 | [diff] [blame] | 2230 | // Explicit clinit checks triggered by static invokes must have been pruned by | 
|  | 2231 | // art::PrepareForRegisterAllocation. | 
|  | 2232 | DCHECK(!invoke->IsStaticWithExplicitClinitCheck()); | 
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 2233 |  | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2234 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
|  | 2235 | return; | 
| Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 2236 | } | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2237 |  | 
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2238 | LocationSummary* locations = invoke->GetLocations(); | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 2239 | codegen_->GenerateStaticOrDirectCall( | 
| Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 2240 | invoke, locations->HasTemps() ? locations->GetTemp(0) : Location::NoLocation()); | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2241 | } | 
|  | 2242 |  | 
|  | 2243 | void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 2244 | IntrinsicLocationsBuilderX86 intrinsic(codegen_); | 
|  | 2245 | if (intrinsic.TryDispatch(invoke)) { | 
|  | 2246 | return; | 
|  | 2247 | } | 
|  | 2248 |  | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2249 | HandleInvoke(invoke); | 
|  | 2250 | } | 
|  | 2251 |  | 
|  | 2252 | void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) { | 
| Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 2253 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; | 
| Nicolas Geoffray | fd88f16 | 2015-06-03 11:23:52 +0100 | [diff] [blame] | 2254 | CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor); | 
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2255 | } | 
|  | 2256 |  | 
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 2257 | void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) { | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2258 | if (TryGenerateIntrinsicCode(invoke, codegen_)) { | 
|  | 2259 | return; | 
|  | 2260 | } | 
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2261 |  | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 2262 | codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0)); | 
| Nicolas Geoffray | f12feb8 | 2014-07-17 18:32:41 +0100 | [diff] [blame] | 2263 | DCHECK(!codegen_->IsLeafMethod()); | 
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2264 | } | 
|  | 2265 |  | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2266 | void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2267 | // This call to HandleInvoke allocates a temporary (core) register | 
|  | 2268 | // which is also used to transfer the hidden argument from FP to | 
|  | 2269 | // core register. | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2270 | HandleInvoke(invoke); | 
|  | 2271 | // Add the hidden argument. | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2272 | invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM7)); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2273 | } | 
|  | 2274 |  | 
|  | 2275 | void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) { | 
|  | 2276 | // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2277 | LocationSummary* locations = invoke->GetLocations(); | 
|  | 2278 | Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 2279 | XmmRegister hidden_reg = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2280 | Location receiver = locations->InAt(0); | 
|  | 2281 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
|  | 2282 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2283 | // Set the hidden argument. This is safe to do this here, as XMM7 | 
|  | 2284 | // won't be modified thereafter, before the `call` instruction. | 
|  | 2285 | DCHECK_EQ(XMM7, hidden_reg); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2286 | __ movl(temp, Immediate(invoke->GetDexMethodIndex())); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2287 | __ movd(hidden_reg, temp); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2288 |  | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2289 | if (receiver.IsStackSlot()) { | 
|  | 2290 | __ movl(temp, Address(ESP, receiver.GetStackIndex())); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2291 | // /* HeapReference<Class> */ temp = temp->klass_ | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2292 | __ movl(temp, Address(temp, class_offset)); | 
|  | 2293 | } else { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2294 | // /* HeapReference<Class> */ temp = receiver->klass_ | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2295 | __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset)); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2296 | } | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2297 | codegen_->MaybeRecordImplicitNullCheck(invoke); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2298 | // Instead of simply (possibly) unpoisoning `temp` here, we should | 
|  | 2299 | // emit a read barrier for the previous class reference load. | 
|  | 2300 | // However this is not required in practice, as this is an | 
|  | 2301 | // intermediate/temporary reference and because the current | 
|  | 2302 | // concurrent copying collector keeps the from-space memory | 
|  | 2303 | // intact/accessible until the end of the marking phase (the | 
|  | 2304 | // concurrent copying collector may not in the future). | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2305 | __ MaybeUnpoisonHeapReference(temp); | 
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2306 | // temp = temp->GetAddressOfIMT() | 
|  | 2307 | __ movl(temp, | 
|  | 2308 | Address(temp, mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2309 | // temp = temp->GetImtEntryAt(method_offset); | 
| Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 2310 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( | 
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 2311 | invoke->GetImtIndex(), kX86PointerSize)); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2312 | __ movl(temp, Address(temp, method_offset)); | 
|  | 2313 | // call temp->GetEntryPoint(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2314 | __ call(Address(temp, | 
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2315 | ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); | 
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 2316 |  | 
|  | 2317 | DCHECK(!codegen_->IsLeafMethod()); | 
|  | 2318 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); | 
|  | 2319 | } | 
|  | 2320 |  | 
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2321 | void LocationsBuilderX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { | 
|  | 2322 | HandleInvoke(invoke); | 
|  | 2323 | } | 
|  | 2324 |  | 
|  | 2325 | void InstructionCodeGeneratorX86::VisitInvokePolymorphic(HInvokePolymorphic* invoke) { | 
|  | 2326 | codegen_->GenerateInvokePolymorphicCall(invoke); | 
|  | 2327 | } | 
|  | 2328 |  | 
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 2329 | void LocationsBuilderX86::VisitInvokeCustom(HInvokeCustom* invoke) { | 
|  | 2330 | HandleInvoke(invoke); | 
|  | 2331 | } | 
|  | 2332 |  | 
|  | 2333 | void InstructionCodeGeneratorX86::VisitInvokeCustom(HInvokeCustom* invoke) { | 
|  | 2334 | codegen_->GenerateInvokeCustomCall(invoke); | 
|  | 2335 | } | 
|  | 2336 |  | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2337 | void LocationsBuilderX86::VisitNeg(HNeg* neg) { | 
|  | 2338 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2339 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2340 | switch (neg->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2341 | case DataType::Type::kInt32: | 
|  | 2342 | case DataType::Type::kInt64: | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2343 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2344 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2345 | break; | 
|  | 2346 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2347 | case DataType::Type::kFloat32: | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2348 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2349 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2350 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 2351 | locations->AddTemp(Location::RequiresFpuRegister()); | 
|  | 2352 | break; | 
|  | 2353 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2354 | case DataType::Type::kFloat64: | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2355 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2356 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2357 | locations->AddTemp(Location::RequiresFpuRegister()); | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2358 | break; | 
|  | 2359 |  | 
|  | 2360 | default: | 
|  | 2361 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); | 
|  | 2362 | } | 
|  | 2363 | } | 
|  | 2364 |  | 
|  | 2365 | void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) { | 
|  | 2366 | LocationSummary* locations = neg->GetLocations(); | 
|  | 2367 | Location out = locations->Out(); | 
|  | 2368 | Location in = locations->InAt(0); | 
|  | 2369 | switch (neg->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2370 | case DataType::Type::kInt32: | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2371 | DCHECK(in.IsRegister()); | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2372 | DCHECK(in.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2373 | __ negl(out.AsRegister<Register>()); | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2374 | break; | 
|  | 2375 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2376 | case DataType::Type::kInt64: | 
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2377 | DCHECK(in.IsRegisterPair()); | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2378 | DCHECK(in.Equals(out)); | 
| Roland Levillain | 2e07b4f | 2014-10-23 18:12:09 +0100 | [diff] [blame] | 2379 | __ negl(out.AsRegisterPairLow<Register>()); | 
|  | 2380 | // Negation is similar to subtraction from zero.  The least | 
|  | 2381 | // significant byte triggers a borrow when it is different from | 
|  | 2382 | // zero; to take it into account, add 1 to the most significant | 
|  | 2383 | // byte if the carry flag (CF) is set to 1 after the first NEGL | 
|  | 2384 | // operation. | 
|  | 2385 | __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0)); | 
|  | 2386 | __ negl(out.AsRegisterPairHigh<Register>()); | 
|  | 2387 | break; | 
|  | 2388 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2389 | case DataType::Type::kFloat32: { | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2390 | DCHECK(in.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2391 | Register constant = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 2392 | XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2393 | // Implement float negation with an exclusive or with value | 
|  | 2394 | // 0x80000000 (mask for bit 31, representing the sign of a | 
|  | 2395 | // single-precision floating-point number). | 
|  | 2396 | __ movl(constant, Immediate(INT32_C(0x80000000))); | 
|  | 2397 | __ movd(mask, constant); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2398 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2399 | break; | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2400 | } | 
| Roland Levillain | 3dbcb38 | 2014-10-28 17:30:07 +0000 | [diff] [blame] | 2401 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2402 | case DataType::Type::kFloat64: { | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2403 | DCHECK(in.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2404 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2405 | // Implement double negation with an exclusive or with value | 
|  | 2406 | // 0x8000000000000000 (mask for bit 63, representing the sign of | 
|  | 2407 | // a double-precision floating-point number). | 
|  | 2408 | __ LoadLongConstant(mask, INT64_C(0x8000000000000000)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2409 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2410 | break; | 
| Roland Levillain | 5368c21 | 2014-11-27 15:03:41 +0000 | [diff] [blame] | 2411 | } | 
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2412 |  | 
|  | 2413 | default: | 
|  | 2414 | LOG(FATAL) << "Unexpected neg type " << neg->GetResultType(); | 
|  | 2415 | } | 
|  | 2416 | } | 
|  | 2417 |  | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2418 | void LocationsBuilderX86::VisitX86FPNeg(HX86FPNeg* neg) { | 
|  | 2419 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2420 | new (GetGraph()->GetAllocator()) LocationSummary(neg, LocationSummary::kNoCall); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2421 | DCHECK(DataType::IsFloatingPointType(neg->GetType())); | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2422 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2423 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 2424 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 2425 | locations->AddTemp(Location::RequiresFpuRegister()); | 
|  | 2426 | } | 
|  | 2427 |  | 
|  | 2428 | void InstructionCodeGeneratorX86::VisitX86FPNeg(HX86FPNeg* neg) { | 
|  | 2429 | LocationSummary* locations = neg->GetLocations(); | 
|  | 2430 | Location out = locations->Out(); | 
|  | 2431 | DCHECK(locations->InAt(0).Equals(out)); | 
|  | 2432 |  | 
|  | 2433 | Register constant_area = locations->InAt(1).AsRegister<Register>(); | 
|  | 2434 | XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2435 | if (neg->GetType() == DataType::Type::kFloat32) { | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2436 | __ movss(mask, codegen_->LiteralInt32Address(INT32_C(0x80000000), | 
|  | 2437 | neg->GetBaseMethodAddress(), | 
|  | 2438 | constant_area)); | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2439 | __ xorps(out.AsFpuRegister<XmmRegister>(), mask); | 
|  | 2440 | } else { | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 2441 | __ movsd(mask, codegen_->LiteralInt64Address(INT64_C(0x8000000000000000), | 
|  | 2442 | neg->GetBaseMethodAddress(), | 
|  | 2443 | constant_area)); | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 2444 | __ xorpd(out.AsFpuRegister<XmmRegister>(), mask); | 
|  | 2445 | } | 
|  | 2446 | } | 
|  | 2447 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2448 | void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2449 | DataType::Type result_type = conversion->GetResultType(); | 
|  | 2450 | DataType::Type input_type = conversion->GetInputType(); | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2451 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) | 
|  | 2452 | << input_type << " -> " << result_type; | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2453 |  | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2454 | // The float-to-long and double-to-long type conversions rely on a | 
|  | 2455 | // call to the runtime. | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2456 | LocationSummary::CallKind call_kind = | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2457 | ((input_type == DataType::Type::kFloat32 || input_type == DataType::Type::kFloat64) | 
|  | 2458 | && result_type == DataType::Type::kInt64) | 
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2459 | ? LocationSummary::kCallOnMainOnly | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2460 | : LocationSummary::kNoCall; | 
|  | 2461 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2462 | new (GetGraph()->GetAllocator()) LocationSummary(conversion, call_kind); | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2463 |  | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2464 | switch (result_type) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2465 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2466 | case DataType::Type::kInt8: | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2467 | switch (input_type) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2468 | case DataType::Type::kUint8: | 
|  | 2469 | case DataType::Type::kInt8: | 
|  | 2470 | case DataType::Type::kUint16: | 
|  | 2471 | case DataType::Type::kInt16: | 
|  | 2472 | case DataType::Type::kInt32: | 
|  | 2473 | locations->SetInAt(0, Location::ByteRegisterOrConstant(ECX, conversion->InputAt(0))); | 
|  | 2474 | // Make the output overlap to please the register allocator. This greatly simplifies | 
|  | 2475 | // the validation of the linear scan implementation | 
|  | 2476 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); | 
|  | 2477 | break; | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2478 | case DataType::Type::kInt64: { | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2479 | HInstruction* input = conversion->InputAt(0); | 
|  | 2480 | Location input_location = input->IsConstant() | 
|  | 2481 | ? Location::ConstantLocation(input->AsConstant()) | 
|  | 2482 | : Location::RegisterPairLocation(EAX, EDX); | 
|  | 2483 | locations->SetInAt(0, input_location); | 
|  | 2484 | // Make the output overlap to please the register allocator. This greatly simplifies | 
|  | 2485 | // the validation of the linear scan implementation | 
|  | 2486 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); | 
|  | 2487 | break; | 
|  | 2488 | } | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2489 |  | 
|  | 2490 | default: | 
|  | 2491 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2492 | << " to " << result_type; | 
|  | 2493 | } | 
|  | 2494 | break; | 
|  | 2495 |  | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2496 | case DataType::Type::kUint16: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2497 | case DataType::Type::kInt16: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2498 | DCHECK(DataType::IsIntegralType(input_type)) << input_type; | 
|  | 2499 | locations->SetInAt(0, Location::Any()); | 
|  | 2500 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2501 | break; | 
|  | 2502 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2503 | case DataType::Type::kInt32: | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2504 | switch (input_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2505 | case DataType::Type::kInt64: | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2506 | locations->SetInAt(0, Location::Any()); | 
|  | 2507 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 2508 | break; | 
|  | 2509 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2510 | case DataType::Type::kFloat32: | 
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2511 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2512 | locations->SetOut(Location::RequiresRegister()); | 
|  | 2513 | locations->AddTemp(Location::RequiresFpuRegister()); | 
|  | 2514 | break; | 
|  | 2515 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2516 | case DataType::Type::kFloat64: | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2517 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2518 | locations->SetOut(Location::RequiresRegister()); | 
|  | 2519 | locations->AddTemp(Location::RequiresFpuRegister()); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2520 | break; | 
|  | 2521 |  | 
|  | 2522 | default: | 
|  | 2523 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2524 | << " to " << result_type; | 
|  | 2525 | } | 
|  | 2526 | break; | 
|  | 2527 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2528 | case DataType::Type::kInt64: | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2529 | switch (input_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2530 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2531 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2532 | case DataType::Type::kInt8: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2533 | case DataType::Type::kUint16: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2534 | case DataType::Type::kInt16: | 
|  | 2535 | case DataType::Type::kInt32: | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2536 | locations->SetInAt(0, Location::RegisterLocation(EAX)); | 
|  | 2537 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); | 
|  | 2538 | break; | 
|  | 2539 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2540 | case DataType::Type::kFloat32: | 
|  | 2541 | case DataType::Type::kFloat64: { | 
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2542 | InvokeRuntimeCallingConvention calling_convention; | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2543 | XmmRegister parameter = calling_convention.GetFpuRegisterAt(0); | 
|  | 2544 | locations->SetInAt(0, Location::FpuRegisterLocation(parameter)); | 
|  | 2545 |  | 
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2546 | // The runtime helper puts the result in EAX, EDX. | 
|  | 2547 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); | 
| Vladimir Marko | 949c91f | 2015-01-27 10:48:44 +0000 | [diff] [blame] | 2548 | } | 
| Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 2549 | break; | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2550 |  | 
|  | 2551 | default: | 
|  | 2552 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2553 | << " to " << result_type; | 
|  | 2554 | } | 
|  | 2555 | break; | 
|  | 2556 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2557 | case DataType::Type::kFloat32: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2558 | switch (input_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2559 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2560 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2561 | case DataType::Type::kInt8: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2562 | case DataType::Type::kUint16: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2563 | case DataType::Type::kInt16: | 
|  | 2564 | case DataType::Type::kInt32: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2565 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2566 | locations->SetOut(Location::RequiresFpuRegister()); | 
|  | 2567 | break; | 
|  | 2568 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2569 | case DataType::Type::kInt64: | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2570 | locations->SetInAt(0, Location::Any()); | 
|  | 2571 | locations->SetOut(Location::Any()); | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2572 | break; | 
|  | 2573 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2574 | case DataType::Type::kFloat64: | 
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2575 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2576 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2577 | break; | 
|  | 2578 |  | 
|  | 2579 | default: | 
|  | 2580 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2581 | << " to " << result_type; | 
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2582 | } | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2583 | break; | 
|  | 2584 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2585 | case DataType::Type::kFloat64: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2586 | switch (input_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2587 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2588 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2589 | case DataType::Type::kInt8: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2590 | case DataType::Type::kUint16: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2591 | case DataType::Type::kInt16: | 
|  | 2592 | case DataType::Type::kInt32: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2593 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2594 | locations->SetOut(Location::RequiresFpuRegister()); | 
|  | 2595 | break; | 
|  | 2596 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2597 | case DataType::Type::kInt64: | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2598 | locations->SetInAt(0, Location::Any()); | 
|  | 2599 | locations->SetOut(Location::Any()); | 
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2600 | break; | 
|  | 2601 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2602 | case DataType::Type::kFloat32: | 
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2603 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 2604 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2605 | break; | 
|  | 2606 |  | 
|  | 2607 | default: | 
|  | 2608 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2609 | << " to " << result_type; | 
|  | 2610 | } | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2611 | break; | 
|  | 2612 |  | 
|  | 2613 | default: | 
|  | 2614 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2615 | << " to " << result_type; | 
|  | 2616 | } | 
|  | 2617 | } | 
|  | 2618 |  | 
|  | 2619 | void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) { | 
|  | 2620 | LocationSummary* locations = conversion->GetLocations(); | 
|  | 2621 | Location out = locations->Out(); | 
|  | 2622 | Location in = locations->InAt(0); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2623 | DataType::Type result_type = conversion->GetResultType(); | 
|  | 2624 | DataType::Type input_type = conversion->GetInputType(); | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2625 | DCHECK(!DataType::IsTypeConversionImplicit(input_type, result_type)) | 
|  | 2626 | << input_type << " -> " << result_type; | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2627 | switch (result_type) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2628 | case DataType::Type::kUint8: | 
|  | 2629 | switch (input_type) { | 
|  | 2630 | case DataType::Type::kInt8: | 
|  | 2631 | case DataType::Type::kUint16: | 
|  | 2632 | case DataType::Type::kInt16: | 
|  | 2633 | case DataType::Type::kInt32: | 
|  | 2634 | if (in.IsRegister()) { | 
|  | 2635 | __ movzxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); | 
|  | 2636 | } else { | 
|  | 2637 | DCHECK(in.GetConstant()->IsIntConstant()); | 
|  | 2638 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); | 
|  | 2639 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); | 
|  | 2640 | } | 
|  | 2641 | break; | 
|  | 2642 | case DataType::Type::kInt64: | 
|  | 2643 | if (in.IsRegisterPair()) { | 
|  | 2644 | __ movzxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); | 
|  | 2645 | } else { | 
|  | 2646 | DCHECK(in.GetConstant()->IsLongConstant()); | 
|  | 2647 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 2648 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint8_t>(value))); | 
|  | 2649 | } | 
|  | 2650 | break; | 
|  | 2651 |  | 
|  | 2652 | default: | 
|  | 2653 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2654 | << " to " << result_type; | 
|  | 2655 | } | 
|  | 2656 | break; | 
|  | 2657 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2658 | case DataType::Type::kInt8: | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2659 | switch (input_type) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2660 | case DataType::Type::kUint8: | 
|  | 2661 | case DataType::Type::kUint16: | 
|  | 2662 | case DataType::Type::kInt16: | 
|  | 2663 | case DataType::Type::kInt32: | 
|  | 2664 | if (in.IsRegister()) { | 
|  | 2665 | __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>()); | 
|  | 2666 | } else { | 
|  | 2667 | DCHECK(in.GetConstant()->IsIntConstant()); | 
|  | 2668 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); | 
|  | 2669 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); | 
|  | 2670 | } | 
|  | 2671 | break; | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2672 | case DataType::Type::kInt64: | 
| Vladimir Marko | b52bbde | 2016-02-12 12:06:05 +0000 | [diff] [blame] | 2673 | if (in.IsRegisterPair()) { | 
|  | 2674 | __ movsxb(out.AsRegister<Register>(), in.AsRegisterPairLow<ByteRegister>()); | 
|  | 2675 | } else { | 
|  | 2676 | DCHECK(in.GetConstant()->IsLongConstant()); | 
|  | 2677 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 2678 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value))); | 
|  | 2679 | } | 
|  | 2680 | break; | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2681 |  | 
|  | 2682 | default: | 
|  | 2683 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2684 | << " to " << result_type; | 
|  | 2685 | } | 
|  | 2686 | break; | 
|  | 2687 |  | 
|  | 2688 | case DataType::Type::kUint16: | 
|  | 2689 | switch (input_type) { | 
|  | 2690 | case DataType::Type::kInt8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2691 | case DataType::Type::kInt16: | 
|  | 2692 | case DataType::Type::kInt32: | 
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2693 | if (in.IsRegister()) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2694 | __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>()); | 
|  | 2695 | } else if (in.IsStackSlot()) { | 
|  | 2696 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2697 | } else { | 
|  | 2698 | DCHECK(in.GetConstant()->IsIntConstant()); | 
|  | 2699 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2700 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); | 
|  | 2701 | } | 
|  | 2702 | break; | 
|  | 2703 | case DataType::Type::kInt64: | 
|  | 2704 | if (in.IsRegisterPair()) { | 
|  | 2705 | __ movzxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); | 
|  | 2706 | } else if (in.IsDoubleStackSlot()) { | 
|  | 2707 | __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
|  | 2708 | } else { | 
|  | 2709 | DCHECK(in.GetConstant()->IsLongConstant()); | 
|  | 2710 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 2711 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value))); | 
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 2712 | } | 
| Roland Levillain | 51d3fc4 | 2014-11-13 14:11:42 +0000 | [diff] [blame] | 2713 | break; | 
|  | 2714 |  | 
|  | 2715 | default: | 
|  | 2716 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2717 | << " to " << result_type; | 
|  | 2718 | } | 
|  | 2719 | break; | 
|  | 2720 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2721 | case DataType::Type::kInt16: | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2722 | switch (input_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2723 | case DataType::Type::kUint16: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2724 | case DataType::Type::kInt32: | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2725 | if (in.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2726 | __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>()); | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2727 | } else if (in.IsStackSlot()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2728 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2729 | } else { | 
|  | 2730 | DCHECK(in.GetConstant()->IsIntConstant()); | 
|  | 2731 | int32_t value = in.GetConstant()->AsIntConstant()->GetValue(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2732 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2733 | } | 
|  | 2734 | break; | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2735 | case DataType::Type::kInt64: | 
|  | 2736 | if (in.IsRegisterPair()) { | 
|  | 2737 | __ movsxw(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); | 
|  | 2738 | } else if (in.IsDoubleStackSlot()) { | 
|  | 2739 | __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
|  | 2740 | } else { | 
|  | 2741 | DCHECK(in.GetConstant()->IsLongConstant()); | 
|  | 2742 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 2743 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value))); | 
|  | 2744 | } | 
|  | 2745 | break; | 
| Roland Levillain | 01a8d71 | 2014-11-14 16:27:39 +0000 | [diff] [blame] | 2746 |  | 
|  | 2747 | default: | 
|  | 2748 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2749 | << " to " << result_type; | 
|  | 2750 | } | 
|  | 2751 | break; | 
|  | 2752 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2753 | case DataType::Type::kInt32: | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2754 | switch (input_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2755 | case DataType::Type::kInt64: | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2756 | if (in.IsRegisterPair()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2757 | __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>()); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2758 | } else if (in.IsDoubleStackSlot()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2759 | __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex())); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2760 | } else { | 
|  | 2761 | DCHECK(in.IsConstant()); | 
|  | 2762 | DCHECK(in.GetConstant()->IsLongConstant()); | 
|  | 2763 | int64_t value = in.GetConstant()->AsLongConstant()->GetValue(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2764 | __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value))); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2765 | } | 
|  | 2766 | break; | 
|  | 2767 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2768 | case DataType::Type::kFloat32: { | 
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2769 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); | 
|  | 2770 | Register output = out.AsRegister<Register>(); | 
|  | 2771 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2772 | NearLabel done, nan; | 
| Roland Levillain | 3f8f936 | 2014-12-02 17:45:01 +0000 | [diff] [blame] | 2773 |  | 
|  | 2774 | __ movl(output, Immediate(kPrimIntMax)); | 
|  | 2775 | // temp = int-to-float(output) | 
|  | 2776 | __ cvtsi2ss(temp, output); | 
|  | 2777 | // if input >= temp goto done | 
|  | 2778 | __ comiss(input, temp); | 
|  | 2779 | __ j(kAboveEqual, &done); | 
|  | 2780 | // if input == NaN goto nan | 
|  | 2781 | __ j(kUnordered, &nan); | 
|  | 2782 | // output = float-to-int-truncate(input) | 
|  | 2783 | __ cvttss2si(output, input); | 
|  | 2784 | __ jmp(&done); | 
|  | 2785 | __ Bind(&nan); | 
|  | 2786 | //  output = 0 | 
|  | 2787 | __ xorl(output, output); | 
|  | 2788 | __ Bind(&done); | 
|  | 2789 | break; | 
|  | 2790 | } | 
|  | 2791 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2792 | case DataType::Type::kFloat64: { | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2793 | XmmRegister input = in.AsFpuRegister<XmmRegister>(); | 
|  | 2794 | Register output = out.AsRegister<Register>(); | 
|  | 2795 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2796 | NearLabel done, nan; | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2797 |  | 
|  | 2798 | __ movl(output, Immediate(kPrimIntMax)); | 
|  | 2799 | // temp = int-to-double(output) | 
|  | 2800 | __ cvtsi2sd(temp, output); | 
|  | 2801 | // if input >= temp goto done | 
|  | 2802 | __ comisd(input, temp); | 
|  | 2803 | __ j(kAboveEqual, &done); | 
|  | 2804 | // if input == NaN goto nan | 
|  | 2805 | __ j(kUnordered, &nan); | 
|  | 2806 | // output = double-to-int-truncate(input) | 
|  | 2807 | __ cvttsd2si(output, input); | 
|  | 2808 | __ jmp(&done); | 
|  | 2809 | __ Bind(&nan); | 
|  | 2810 | //  output = 0 | 
|  | 2811 | __ xorl(output, output); | 
|  | 2812 | __ Bind(&done); | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2813 | break; | 
| Roland Levillain | 4c0b61f | 2014-12-05 12:06:01 +0000 | [diff] [blame] | 2814 | } | 
| Roland Levillain | 946e143 | 2014-11-11 17:35:19 +0000 | [diff] [blame] | 2815 |  | 
|  | 2816 | default: | 
|  | 2817 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2818 | << " to " << result_type; | 
|  | 2819 | } | 
|  | 2820 | break; | 
|  | 2821 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2822 | case DataType::Type::kInt64: | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2823 | switch (input_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2824 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2825 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2826 | case DataType::Type::kInt8: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2827 | case DataType::Type::kUint16: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2828 | case DataType::Type::kInt16: | 
|  | 2829 | case DataType::Type::kInt32: | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2830 | DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX); | 
|  | 2831 | DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2832 | DCHECK_EQ(in.AsRegister<Register>(), EAX); | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2833 | __ cdq(); | 
|  | 2834 | break; | 
|  | 2835 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2836 | case DataType::Type::kFloat32: | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2837 | codegen_->InvokeRuntime(kQuickF2l, conversion, conversion->GetDexPc()); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2838 | CheckEntrypointTypes<kQuickF2l, int64_t, float>(); | 
| Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 2839 | break; | 
|  | 2840 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2841 | case DataType::Type::kFloat64: | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 2842 | codegen_->InvokeRuntime(kQuickD2l, conversion, conversion->GetDexPc()); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 2843 | CheckEntrypointTypes<kQuickD2l, int64_t, double>(); | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2844 | break; | 
|  | 2845 |  | 
|  | 2846 | default: | 
|  | 2847 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2848 | << " to " << result_type; | 
|  | 2849 | } | 
|  | 2850 | break; | 
|  | 2851 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2852 | case DataType::Type::kFloat32: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2853 | switch (input_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2854 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2855 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2856 | case DataType::Type::kInt8: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2857 | case DataType::Type::kUint16: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2858 | case DataType::Type::kInt16: | 
|  | 2859 | case DataType::Type::kInt32: | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2860 | __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2861 | break; | 
|  | 2862 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2863 | case DataType::Type::kInt64: { | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2864 | size_t adjustment = 0; | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2865 |  | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2866 | // Create stack space for the call to | 
|  | 2867 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstps below. | 
|  | 2868 | // TODO: enhance register allocator to ask for stack temporaries. | 
|  | 2869 | if (!in.IsDoubleStackSlot() || !out.IsStackSlot()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2870 | adjustment = DataType::Size(DataType::Type::kInt64); | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2871 | __ subl(ESP, Immediate(adjustment)); | 
|  | 2872 | } | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2873 |  | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2874 | // Load the value to the FP stack, using temporaries if needed. | 
|  | 2875 | PushOntoFPStack(in, 0, adjustment, false, true); | 
|  | 2876 |  | 
|  | 2877 | if (out.IsStackSlot()) { | 
|  | 2878 | __ fstps(Address(ESP, out.GetStackIndex() + adjustment)); | 
|  | 2879 | } else { | 
|  | 2880 | __ fstps(Address(ESP, 0)); | 
|  | 2881 | Location stack_temp = Location::StackSlot(0); | 
|  | 2882 | codegen_->Move32(out, stack_temp); | 
|  | 2883 | } | 
|  | 2884 |  | 
|  | 2885 | // Remove the temporary stack space we allocated. | 
|  | 2886 | if (adjustment != 0) { | 
|  | 2887 | __ addl(ESP, Immediate(adjustment)); | 
|  | 2888 | } | 
| Roland Levillain | 6d0e483 | 2014-11-27 18:31:21 +0000 | [diff] [blame] | 2889 | break; | 
|  | 2890 | } | 
|  | 2891 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2892 | case DataType::Type::kFloat64: | 
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2893 | __ cvtsd2ss(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2894 | break; | 
|  | 2895 |  | 
|  | 2896 | default: | 
|  | 2897 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2898 | << " to " << result_type; | 
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2899 | } | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2900 | break; | 
|  | 2901 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2902 | case DataType::Type::kFloat64: | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2903 | switch (input_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2904 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2905 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2906 | case DataType::Type::kInt8: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 2907 | case DataType::Type::kUint16: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2908 | case DataType::Type::kInt16: | 
|  | 2909 | case DataType::Type::kInt32: | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 2910 | __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>()); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2911 | break; | 
|  | 2912 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2913 | case DataType::Type::kInt64: { | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2914 | size_t adjustment = 0; | 
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2915 |  | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2916 | // Create stack space for the call to | 
|  | 2917 | // InstructionCodeGeneratorX86::PushOntoFPStack and/or X86Assembler::fstpl below. | 
|  | 2918 | // TODO: enhance register allocator to ask for stack temporaries. | 
|  | 2919 | if (!in.IsDoubleStackSlot() || !out.IsDoubleStackSlot()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2920 | adjustment = DataType::Size(DataType::Type::kInt64); | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 2921 | __ subl(ESP, Immediate(adjustment)); | 
|  | 2922 | } | 
|  | 2923 |  | 
|  | 2924 | // Load the value to the FP stack, using temporaries if needed. | 
|  | 2925 | PushOntoFPStack(in, 0, adjustment, false, true); | 
|  | 2926 |  | 
|  | 2927 | if (out.IsDoubleStackSlot()) { | 
|  | 2928 | __ fstpl(Address(ESP, out.GetStackIndex() + adjustment)); | 
|  | 2929 | } else { | 
|  | 2930 | __ fstpl(Address(ESP, 0)); | 
|  | 2931 | Location stack_temp = Location::DoubleStackSlot(0); | 
|  | 2932 | codegen_->Move64(out, stack_temp); | 
|  | 2933 | } | 
|  | 2934 |  | 
|  | 2935 | // Remove the temporary stack space we allocated. | 
|  | 2936 | if (adjustment != 0) { | 
|  | 2937 | __ addl(ESP, Immediate(adjustment)); | 
|  | 2938 | } | 
| Roland Levillain | 647b9ed | 2014-11-27 12:06:00 +0000 | [diff] [blame] | 2939 | break; | 
|  | 2940 | } | 
|  | 2941 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2942 | case DataType::Type::kFloat32: | 
| Roland Levillain | 8964e2b | 2014-12-04 12:10:50 +0000 | [diff] [blame] | 2943 | __ cvtss2sd(out.AsFpuRegister<XmmRegister>(), in.AsFpuRegister<XmmRegister>()); | 
| Roland Levillain | cff1374 | 2014-11-17 14:32:17 +0000 | [diff] [blame] | 2944 | break; | 
|  | 2945 |  | 
|  | 2946 | default: | 
|  | 2947 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2948 | << " to " << result_type; | 
| Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 2949 | } | 
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2950 | break; | 
|  | 2951 |  | 
|  | 2952 | default: | 
|  | 2953 | LOG(FATAL) << "Unexpected type conversion from " << input_type | 
|  | 2954 | << " to " << result_type; | 
|  | 2955 | } | 
|  | 2956 | } | 
|  | 2957 |  | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2958 | void LocationsBuilderX86::VisitAdd(HAdd* add) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2959 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2960 | new (GetGraph()->GetAllocator()) LocationSummary(add, LocationSummary::kNoCall); | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2961 | switch (add->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2962 | case DataType::Type::kInt32: { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 2963 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2964 | locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1))); | 
|  | 2965 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 2966 | break; | 
|  | 2967 | } | 
|  | 2968 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2969 | case DataType::Type::kInt64: { | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 2970 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 2971 | locations->SetInAt(1, Location::Any()); | 
|  | 2972 | locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2973 | break; | 
|  | 2974 | } | 
|  | 2975 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2976 | case DataType::Type::kFloat32: | 
|  | 2977 | case DataType::Type::kFloat64: { | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2978 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2979 | if (add->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 2980 | DCHECK(add->InputAt(1)->IsEmittedAtUseSite()); | 
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 2981 | } else if (add->InputAt(1)->IsConstant()) { | 
|  | 2982 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2983 | } else { | 
|  | 2984 | locations->SetInAt(1, Location::Any()); | 
|  | 2985 | } | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2986 | locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2987 | break; | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2988 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2989 |  | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2990 | default: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2991 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); | 
| Elliott Hughes | c1896c9 | 2018-11-29 11:33:18 -0800 | [diff] [blame] | 2992 | UNREACHABLE(); | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2993 | } | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2994 | } | 
|  | 2995 |  | 
|  | 2996 | void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) { | 
|  | 2997 | LocationSummary* locations = add->GetLocations(); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 2998 | Location first = locations->InAt(0); | 
|  | 2999 | Location second = locations->InAt(1); | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3000 | Location out = locations->Out(); | 
|  | 3001 |  | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3002 | switch (add->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3003 | case DataType::Type::kInt32: { | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3004 | if (second.IsRegister()) { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3005 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { | 
|  | 3006 | __ addl(out.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Mark Mendell | 33bf245 | 2015-05-27 10:08:24 -0400 | [diff] [blame] | 3007 | } else if (out.AsRegister<Register>() == second.AsRegister<Register>()) { | 
|  | 3008 | __ addl(out.AsRegister<Register>(), first.AsRegister<Register>()); | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3009 | } else { | 
|  | 3010 | __ leal(out.AsRegister<Register>(), Address( | 
|  | 3011 | first.AsRegister<Register>(), second.AsRegister<Register>(), TIMES_1, 0)); | 
|  | 3012 | } | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3013 | } else if (second.IsConstant()) { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3014 | int32_t value = second.GetConstant()->AsIntConstant()->GetValue(); | 
|  | 3015 | if (out.AsRegister<Register>() == first.AsRegister<Register>()) { | 
|  | 3016 | __ addl(out.AsRegister<Register>(), Immediate(value)); | 
|  | 3017 | } else { | 
|  | 3018 | __ leal(out.AsRegister<Register>(), Address(first.AsRegister<Register>(), value)); | 
|  | 3019 | } | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3020 | } else { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 3021 | DCHECK(first.Equals(locations->Out())); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3022 | __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3023 | } | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3024 | break; | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3025 | } | 
|  | 3026 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3027 | case DataType::Type::kInt64: { | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3028 | if (second.IsRegisterPair()) { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3029 | __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
|  | 3030 | __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3031 | } else if (second.IsDoubleStackSlot()) { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3032 | __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
|  | 3033 | __ adcl(first.AsRegisterPairHigh<Register>(), | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3034 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3035 | } else { | 
|  | 3036 | DCHECK(second.IsConstant()) << second; | 
|  | 3037 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 3038 | __ addl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); | 
|  | 3039 | __ adcl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3040 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3041 | break; | 
|  | 3042 | } | 
|  | 3043 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3044 | case DataType::Type::kFloat32: { | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3045 | if (second.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3046 | __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3047 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3048 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3049 | DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3050 | __ addss(first.AsFpuRegister<XmmRegister>(), | 
|  | 3051 | codegen_->LiteralFloatAddress( | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3052 | const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
|  | 3053 | const_area->GetBaseMethodAddress(), | 
|  | 3054 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3055 | } else { | 
|  | 3056 | DCHECK(second.IsStackSlot()); | 
|  | 3057 | __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3058 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3059 | break; | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3060 | } | 
|  | 3061 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3062 | case DataType::Type::kFloat64: { | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3063 | if (second.IsFpuRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3064 | __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3065 | } else if (add->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3066 | HX86LoadFromConstantTable* const_area = add->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3067 | DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3068 | __ addsd(first.AsFpuRegister<XmmRegister>(), | 
|  | 3069 | codegen_->LiteralDoubleAddress( | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3070 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
|  | 3071 | const_area->GetBaseMethodAddress(), | 
|  | 3072 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3073 | } else { | 
|  | 3074 | DCHECK(second.IsDoubleStackSlot()); | 
|  | 3075 | __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3076 | } | 
|  | 3077 | break; | 
|  | 3078 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3079 |  | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3080 | default: | 
| Nicolas Geoffray | 7fb49da | 2014-10-06 09:12:41 +0100 | [diff] [blame] | 3081 | LOG(FATAL) << "Unexpected add type " << add->GetResultType(); | 
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3082 | } | 
|  | 3083 | } | 
|  | 3084 |  | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3085 | void LocationsBuilderX86::VisitSub(HSub* sub) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 3086 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3087 | new (GetGraph()->GetAllocator()) LocationSummary(sub, LocationSummary::kNoCall); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3088 | switch (sub->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3089 | case DataType::Type::kInt32: | 
|  | 3090 | case DataType::Type::kInt64: { | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3091 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3092 | locations->SetInAt(1, Location::Any()); | 
|  | 3093 | locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3094 | break; | 
|  | 3095 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3096 | case DataType::Type::kFloat32: | 
|  | 3097 | case DataType::Type::kFloat64: { | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3098 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3099 | if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3100 | DCHECK(sub->InputAt(1)->IsEmittedAtUseSite()); | 
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3101 | } else if (sub->InputAt(1)->IsConstant()) { | 
|  | 3102 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3103 | } else { | 
|  | 3104 | locations->SetInAt(1, Location::Any()); | 
|  | 3105 | } | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3106 | locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3107 | break; | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3108 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3109 |  | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3110 | default: | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3111 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3112 | } | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3113 | } | 
|  | 3114 |  | 
|  | 3115 | void InstructionCodeGeneratorX86::VisitSub(HSub* sub) { | 
|  | 3116 | LocationSummary* locations = sub->GetLocations(); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3117 | Location first = locations->InAt(0); | 
|  | 3118 | Location second = locations->InAt(1); | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3119 | DCHECK(first.Equals(locations->Out())); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3120 | switch (sub->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3121 | case DataType::Type::kInt32: { | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3122 | if (second.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3123 | __ subl(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3124 | } else if (second.IsConstant()) { | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 3125 | __ subl(first.AsRegister<Register>(), | 
|  | 3126 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3127 | } else { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3128 | __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3129 | } | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3130 | break; | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3131 | } | 
|  | 3132 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3133 | case DataType::Type::kInt64: { | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3134 | if (second.IsRegisterPair()) { | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3135 | __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
|  | 3136 | __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3137 | } else if (second.IsDoubleStackSlot()) { | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3138 | __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 3139 | __ sbbl(first.AsRegisterPairHigh<Register>(), | 
|  | 3140 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3141 | } else { | 
|  | 3142 | DCHECK(second.IsConstant()) << second; | 
|  | 3143 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 3144 | __ subl(first.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value))); | 
|  | 3145 | __ sbbl(first.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value))); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 3146 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3147 | break; | 
|  | 3148 | } | 
|  | 3149 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3150 | case DataType::Type::kFloat32: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3151 | if (second.IsFpuRegister()) { | 
|  | 3152 | __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
|  | 3153 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3154 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3155 | DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3156 | __ subss(first.AsFpuRegister<XmmRegister>(), | 
|  | 3157 | codegen_->LiteralFloatAddress( | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3158 | const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
|  | 3159 | const_area->GetBaseMethodAddress(), | 
|  | 3160 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3161 | } else { | 
|  | 3162 | DCHECK(second.IsStackSlot()); | 
|  | 3163 | __ subss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
|  | 3164 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3165 | break; | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3166 | } | 
|  | 3167 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3168 | case DataType::Type::kFloat64: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3169 | if (second.IsFpuRegister()) { | 
|  | 3170 | __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
|  | 3171 | } else if (sub->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3172 | HX86LoadFromConstantTable* const_area = sub->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3173 | DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3174 | __ subsd(first.AsFpuRegister<XmmRegister>(), | 
|  | 3175 | codegen_->LiteralDoubleAddress( | 
|  | 3176 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3177 | const_area->GetBaseMethodAddress(), | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3178 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
|  | 3179 | } else { | 
|  | 3180 | DCHECK(second.IsDoubleStackSlot()); | 
|  | 3181 | __ subsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
|  | 3182 | } | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3183 | break; | 
|  | 3184 | } | 
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3185 |  | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3186 | default: | 
| Calin Juravle | 1135168 | 2014-10-23 15:38:15 +0100 | [diff] [blame] | 3187 | LOG(FATAL) << "Unexpected sub type " << sub->GetResultType(); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3188 | } | 
|  | 3189 | } | 
|  | 3190 |  | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3191 | void LocationsBuilderX86::VisitMul(HMul* mul) { | 
|  | 3192 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3193 | new (GetGraph()->GetAllocator()) LocationSummary(mul, LocationSummary::kNoCall); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3194 | switch (mul->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3195 | case DataType::Type::kInt32: | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3196 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3197 | locations->SetInAt(1, Location::Any()); | 
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3198 | if (mul->InputAt(1)->IsIntConstant()) { | 
|  | 3199 | // Can use 3 operand multiply. | 
|  | 3200 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 3201 | } else { | 
|  | 3202 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3203 | } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3204 | break; | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3205 | case DataType::Type::kInt64: { | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3206 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3207 | locations->SetInAt(1, Location::Any()); | 
|  | 3208 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3209 | // Needed for imul on 32bits with 64bits output. | 
|  | 3210 | locations->AddTemp(Location::RegisterLocation(EAX)); | 
|  | 3211 | locations->AddTemp(Location::RegisterLocation(EDX)); | 
|  | 3212 | break; | 
|  | 3213 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3214 | case DataType::Type::kFloat32: | 
|  | 3215 | case DataType::Type::kFloat64: { | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3216 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3217 | if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3218 | DCHECK(mul->InputAt(1)->IsEmittedAtUseSite()); | 
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3219 | } else if (mul->InputAt(1)->IsConstant()) { | 
|  | 3220 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3221 | } else { | 
|  | 3222 | locations->SetInAt(1, Location::Any()); | 
|  | 3223 | } | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3224 | locations->SetOut(Location::SameAsFirstInput()); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3225 | break; | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3226 | } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3227 |  | 
|  | 3228 | default: | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3229 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3230 | } | 
|  | 3231 | } | 
|  | 3232 |  | 
|  | 3233 | void InstructionCodeGeneratorX86::VisitMul(HMul* mul) { | 
|  | 3234 | LocationSummary* locations = mul->GetLocations(); | 
|  | 3235 | Location first = locations->InAt(0); | 
|  | 3236 | Location second = locations->InAt(1); | 
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3237 | Location out = locations->Out(); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3238 |  | 
|  | 3239 | switch (mul->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3240 | case DataType::Type::kInt32: | 
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3241 | // The constant may have ended up in a register, so test explicitly to avoid | 
|  | 3242 | // problems where the output may not be the same as the first operand. | 
|  | 3243 | if (mul->InputAt(1)->IsIntConstant()) { | 
|  | 3244 | Immediate imm(mul->InputAt(1)->AsIntConstant()->GetValue()); | 
|  | 3245 | __ imull(out.AsRegister<Register>(), first.AsRegister<Register>(), imm); | 
|  | 3246 | } else if (second.IsRegister()) { | 
|  | 3247 | DCHECK(first.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3248 | __ imull(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3249 | } else { | 
|  | 3250 | DCHECK(second.IsStackSlot()); | 
| Mark Mendell | 4a2aa4a | 2015-07-27 16:13:10 -0400 | [diff] [blame] | 3251 | DCHECK(first.Equals(out)); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3252 | __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3253 | } | 
|  | 3254 | break; | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3255 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3256 | case DataType::Type::kInt64: { | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3257 | Register in1_hi = first.AsRegisterPairHigh<Register>(); | 
|  | 3258 | Register in1_lo = first.AsRegisterPairLow<Register>(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3259 | Register eax = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 3260 | Register edx = locations->GetTemp(1).AsRegister<Register>(); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3261 |  | 
|  | 3262 | DCHECK_EQ(EAX, eax); | 
|  | 3263 | DCHECK_EQ(EDX, edx); | 
|  | 3264 |  | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3265 | // input: in1 - 64 bits, in2 - 64 bits. | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3266 | // output: in1 | 
|  | 3267 | // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo | 
|  | 3268 | // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32] | 
|  | 3269 | // parts: in1.lo = (in1.lo * in2.lo)[31:0] | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3270 | if (second.IsConstant()) { | 
|  | 3271 | DCHECK(second.GetConstant()->IsLongConstant()); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3272 |  | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3273 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 3274 | int32_t low_value = Low32Bits(value); | 
|  | 3275 | int32_t high_value = High32Bits(value); | 
|  | 3276 | Immediate low(low_value); | 
|  | 3277 | Immediate high(high_value); | 
|  | 3278 |  | 
|  | 3279 | __ movl(eax, high); | 
|  | 3280 | // eax <- in1.lo * in2.hi | 
|  | 3281 | __ imull(eax, in1_lo); | 
|  | 3282 | // in1.hi <- in1.hi * in2.lo | 
|  | 3283 | __ imull(in1_hi, low); | 
|  | 3284 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo | 
|  | 3285 | __ addl(in1_hi, eax); | 
|  | 3286 | // move in2_lo to eax to prepare for double precision | 
|  | 3287 | __ movl(eax, low); | 
|  | 3288 | // edx:eax <- in1.lo * in2.lo | 
|  | 3289 | __ mull(in1_lo); | 
|  | 3290 | // in1.hi <- in2.hi * in1.lo +  in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] | 
|  | 3291 | __ addl(in1_hi, edx); | 
|  | 3292 | // in1.lo <- (in1.lo * in2.lo)[31:0]; | 
|  | 3293 | __ movl(in1_lo, eax); | 
|  | 3294 | } else if (second.IsRegisterPair()) { | 
|  | 3295 | Register in2_hi = second.AsRegisterPairHigh<Register>(); | 
|  | 3296 | Register in2_lo = second.AsRegisterPairLow<Register>(); | 
|  | 3297 |  | 
|  | 3298 | __ movl(eax, in2_hi); | 
|  | 3299 | // eax <- in1.lo * in2.hi | 
|  | 3300 | __ imull(eax, in1_lo); | 
|  | 3301 | // in1.hi <- in1.hi * in2.lo | 
|  | 3302 | __ imull(in1_hi, in2_lo); | 
|  | 3303 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo | 
|  | 3304 | __ addl(in1_hi, eax); | 
|  | 3305 | // move in1_lo to eax to prepare for double precision | 
|  | 3306 | __ movl(eax, in1_lo); | 
|  | 3307 | // edx:eax <- in1.lo * in2.lo | 
|  | 3308 | __ mull(in2_lo); | 
|  | 3309 | // in1.hi <- in2.hi * in1.lo +  in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] | 
|  | 3310 | __ addl(in1_hi, edx); | 
|  | 3311 | // in1.lo <- (in1.lo * in2.lo)[31:0]; | 
|  | 3312 | __ movl(in1_lo, eax); | 
|  | 3313 | } else { | 
|  | 3314 | DCHECK(second.IsDoubleStackSlot()) << second; | 
|  | 3315 | Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize)); | 
|  | 3316 | Address in2_lo(ESP, second.GetStackIndex()); | 
|  | 3317 |  | 
|  | 3318 | __ movl(eax, in2_hi); | 
|  | 3319 | // eax <- in1.lo * in2.hi | 
|  | 3320 | __ imull(eax, in1_lo); | 
|  | 3321 | // in1.hi <- in1.hi * in2.lo | 
|  | 3322 | __ imull(in1_hi, in2_lo); | 
|  | 3323 | // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo | 
|  | 3324 | __ addl(in1_hi, eax); | 
|  | 3325 | // move in1_lo to eax to prepare for double precision | 
|  | 3326 | __ movl(eax, in1_lo); | 
|  | 3327 | // edx:eax <- in1.lo * in2.lo | 
|  | 3328 | __ mull(in2_lo); | 
|  | 3329 | // in1.hi <- in2.hi * in1.lo +  in2.lo * in1.hi + (in1.lo * in2.lo)[63:32] | 
|  | 3330 | __ addl(in1_hi, edx); | 
|  | 3331 | // in1.lo <- (in1.lo * in2.lo)[31:0]; | 
|  | 3332 | __ movl(in1_lo, eax); | 
|  | 3333 | } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3334 |  | 
|  | 3335 | break; | 
|  | 3336 | } | 
|  | 3337 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3338 | case DataType::Type::kFloat32: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3339 | DCHECK(first.Equals(locations->Out())); | 
|  | 3340 | if (second.IsFpuRegister()) { | 
|  | 3341 | __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
|  | 3342 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3343 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3344 | DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3345 | __ mulss(first.AsFpuRegister<XmmRegister>(), | 
|  | 3346 | codegen_->LiteralFloatAddress( | 
|  | 3347 | const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3348 | const_area->GetBaseMethodAddress(), | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3349 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
|  | 3350 | } else { | 
|  | 3351 | DCHECK(second.IsStackSlot()); | 
|  | 3352 | __ mulss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
|  | 3353 | } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3354 | break; | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3355 | } | 
|  | 3356 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3357 | case DataType::Type::kFloat64: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3358 | DCHECK(first.Equals(locations->Out())); | 
|  | 3359 | if (second.IsFpuRegister()) { | 
|  | 3360 | __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
|  | 3361 | } else if (mul->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3362 | HX86LoadFromConstantTable* const_area = mul->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3363 | DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3364 | __ mulsd(first.AsFpuRegister<XmmRegister>(), | 
|  | 3365 | codegen_->LiteralDoubleAddress( | 
|  | 3366 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3367 | const_area->GetBaseMethodAddress(), | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3368 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
|  | 3369 | } else { | 
|  | 3370 | DCHECK(second.IsDoubleStackSlot()); | 
|  | 3371 | __ mulsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
|  | 3372 | } | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3373 | break; | 
|  | 3374 | } | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3375 |  | 
|  | 3376 | default: | 
| Calin Juravle | b5bfa96 | 2014-10-21 18:02:24 +0100 | [diff] [blame] | 3377 | LOG(FATAL) << "Unexpected mul type " << mul->GetResultType(); | 
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3378 | } | 
|  | 3379 | } | 
|  | 3380 |  | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3381 | void InstructionCodeGeneratorX86::PushOntoFPStack(Location source, | 
|  | 3382 | uint32_t temp_offset, | 
|  | 3383 | uint32_t stack_adjustment, | 
|  | 3384 | bool is_fp, | 
|  | 3385 | bool is_wide) { | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3386 | if (source.IsStackSlot()) { | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3387 | DCHECK(!is_wide); | 
|  | 3388 | if (is_fp) { | 
|  | 3389 | __ flds(Address(ESP, source.GetStackIndex() + stack_adjustment)); | 
|  | 3390 | } else { | 
|  | 3391 | __ filds(Address(ESP, source.GetStackIndex() + stack_adjustment)); | 
|  | 3392 | } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3393 | } else if (source.IsDoubleStackSlot()) { | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3394 | DCHECK(is_wide); | 
|  | 3395 | if (is_fp) { | 
|  | 3396 | __ fldl(Address(ESP, source.GetStackIndex() + stack_adjustment)); | 
|  | 3397 | } else { | 
|  | 3398 | __ fildl(Address(ESP, source.GetStackIndex() + stack_adjustment)); | 
|  | 3399 | } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3400 | } else { | 
|  | 3401 | // 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] | 3402 | if (!is_wide) { | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3403 | Location stack_temp = Location::StackSlot(temp_offset); | 
|  | 3404 | codegen_->Move32(stack_temp, source); | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3405 | if (is_fp) { | 
|  | 3406 | __ flds(Address(ESP, temp_offset)); | 
|  | 3407 | } else { | 
|  | 3408 | __ filds(Address(ESP, temp_offset)); | 
|  | 3409 | } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3410 | } else { | 
|  | 3411 | Location stack_temp = Location::DoubleStackSlot(temp_offset); | 
|  | 3412 | codegen_->Move64(stack_temp, source); | 
| Roland Levillain | 232ade0 | 2015-04-20 15:14:36 +0100 | [diff] [blame] | 3413 | if (is_fp) { | 
|  | 3414 | __ fldl(Address(ESP, temp_offset)); | 
|  | 3415 | } else { | 
|  | 3416 | __ fildl(Address(ESP, temp_offset)); | 
|  | 3417 | } | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3418 | } | 
|  | 3419 | } | 
|  | 3420 | } | 
|  | 3421 |  | 
|  | 3422 | void InstructionCodeGeneratorX86::GenerateRemFP(HRem *rem) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3423 | DataType::Type type = rem->GetResultType(); | 
|  | 3424 | bool is_float = type == DataType::Type::kFloat32; | 
|  | 3425 | size_t elem_size = DataType::Size(type); | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3426 | LocationSummary* locations = rem->GetLocations(); | 
|  | 3427 | Location first = locations->InAt(0); | 
|  | 3428 | Location second = locations->InAt(1); | 
|  | 3429 | Location out = locations->Out(); | 
|  | 3430 |  | 
|  | 3431 | // Create stack space for 2 elements. | 
|  | 3432 | // TODO: enhance register allocator to ask for stack temporaries. | 
|  | 3433 | __ subl(ESP, Immediate(2 * elem_size)); | 
|  | 3434 |  | 
|  | 3435 | // 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] | 3436 | const bool is_wide = !is_float; | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3437 | PushOntoFPStack(second, elem_size, 2 * elem_size, /* is_fp= */ true, is_wide); | 
|  | 3438 | PushOntoFPStack(first, 0, 2 * elem_size, /* is_fp= */ true, is_wide); | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3439 |  | 
|  | 3440 | // Loop doing FPREM until we stabilize. | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 3441 | NearLabel retry; | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3442 | __ Bind(&retry); | 
|  | 3443 | __ fprem(); | 
|  | 3444 |  | 
|  | 3445 | // Move FP status to AX. | 
|  | 3446 | __ fstsw(); | 
|  | 3447 |  | 
|  | 3448 | // And see if the argument reduction is complete. This is signaled by the | 
|  | 3449 | // C2 FPU flag bit set to 0. | 
|  | 3450 | __ andl(EAX, Immediate(kC2ConditionMask)); | 
|  | 3451 | __ j(kNotEqual, &retry); | 
|  | 3452 |  | 
|  | 3453 | // We have settled on the final value. Retrieve it into an XMM register. | 
|  | 3454 | // Store FP top of stack to real stack. | 
|  | 3455 | if (is_float) { | 
|  | 3456 | __ fsts(Address(ESP, 0)); | 
|  | 3457 | } else { | 
|  | 3458 | __ fstl(Address(ESP, 0)); | 
|  | 3459 | } | 
|  | 3460 |  | 
|  | 3461 | // Pop the 2 items from the FP stack. | 
|  | 3462 | __ fucompp(); | 
|  | 3463 |  | 
|  | 3464 | // Load the value from the stack into an XMM register. | 
|  | 3465 | DCHECK(out.IsFpuRegister()) << out; | 
|  | 3466 | if (is_float) { | 
|  | 3467 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); | 
|  | 3468 | } else { | 
|  | 3469 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); | 
|  | 3470 | } | 
|  | 3471 |  | 
|  | 3472 | // And remove the temporary stack space we allocated. | 
|  | 3473 | __ addl(ESP, Immediate(2 * elem_size)); | 
|  | 3474 | } | 
|  | 3475 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3476 |  | 
|  | 3477 | void InstructionCodeGeneratorX86::DivRemOneOrMinusOne(HBinaryOperation* instruction) { | 
|  | 3478 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 3479 |  | 
|  | 3480 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3481 | DCHECK(locations->InAt(1).IsConstant()); | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3482 | DCHECK(locations->InAt(1).GetConstant()->IsIntConstant()); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3483 |  | 
|  | 3484 | Register out_register = locations->Out().AsRegister<Register>(); | 
|  | 3485 | Register input_register = locations->InAt(0).AsRegister<Register>(); | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3486 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3487 |  | 
|  | 3488 | DCHECK(imm == 1 || imm == -1); | 
|  | 3489 |  | 
|  | 3490 | if (instruction->IsRem()) { | 
|  | 3491 | __ xorl(out_register, out_register); | 
|  | 3492 | } else { | 
|  | 3493 | __ movl(out_register, input_register); | 
|  | 3494 | if (imm == -1) { | 
|  | 3495 | __ negl(out_register); | 
|  | 3496 | } | 
|  | 3497 | } | 
|  | 3498 | } | 
|  | 3499 |  | 
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3500 | void InstructionCodeGeneratorX86::RemByPowerOfTwo(HRem* instruction) { | 
|  | 3501 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3502 | Location second = locations->InAt(1); | 
|  | 3503 |  | 
|  | 3504 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 3505 | Register numerator = locations->InAt(0).AsRegister<Register>(); | 
|  | 3506 |  | 
|  | 3507 | int32_t imm = Int64FromConstant(second.GetConstant()); | 
|  | 3508 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); | 
|  | 3509 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); | 
|  | 3510 |  | 
|  | 3511 | Register tmp = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 3512 | NearLabel done; | 
|  | 3513 | __ movl(out, numerator); | 
|  | 3514 | __ andl(out, Immediate(abs_imm-1)); | 
|  | 3515 | __ j(Condition::kZero, &done); | 
|  | 3516 | __ leal(tmp, Address(out, static_cast<int32_t>(~(abs_imm-1)))); | 
|  | 3517 | __ testl(numerator, numerator); | 
|  | 3518 | __ cmovl(Condition::kLess, out, tmp); | 
|  | 3519 | __ Bind(&done); | 
|  | 3520 | } | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3521 |  | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3522 | void InstructionCodeGeneratorX86::DivByPowerOfTwo(HDiv* instruction) { | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3523 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3524 |  | 
|  | 3525 | Register out_register = locations->Out().AsRegister<Register>(); | 
|  | 3526 | Register input_register = locations->InAt(0).AsRegister<Register>(); | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3527 | int32_t imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); | 
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3528 | DCHECK(IsPowerOfTwo(AbsOrMin(imm))); | 
|  | 3529 | uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3530 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3531 | Register num = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 3532 |  | 
| Nicolas Geoffray | 68f6289 | 2016-01-04 08:39:49 +0000 | [diff] [blame] | 3533 | __ leal(num, Address(input_register, abs_imm - 1)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3534 | __ testl(input_register, input_register); | 
|  | 3535 | __ cmovl(kGreaterEqual, num, input_register); | 
|  | 3536 | int shift = CTZ(imm); | 
|  | 3537 | __ sarl(num, Immediate(shift)); | 
|  | 3538 |  | 
|  | 3539 | if (imm < 0) { | 
|  | 3540 | __ negl(num); | 
|  | 3541 | } | 
|  | 3542 |  | 
|  | 3543 | __ movl(out_register, num); | 
|  | 3544 | } | 
|  | 3545 |  | 
|  | 3546 | void InstructionCodeGeneratorX86::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) { | 
|  | 3547 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 3548 |  | 
|  | 3549 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3550 | int imm = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); | 
|  | 3551 |  | 
|  | 3552 | Register eax = locations->InAt(0).AsRegister<Register>(); | 
|  | 3553 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 3554 | Register num; | 
|  | 3555 | Register edx; | 
|  | 3556 |  | 
|  | 3557 | if (instruction->IsDiv()) { | 
|  | 3558 | edx = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 3559 | num = locations->GetTemp(1).AsRegister<Register>(); | 
|  | 3560 | } else { | 
|  | 3561 | edx = locations->Out().AsRegister<Register>(); | 
|  | 3562 | num = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 3563 | } | 
|  | 3564 |  | 
|  | 3565 | DCHECK_EQ(EAX, eax); | 
|  | 3566 | DCHECK_EQ(EDX, edx); | 
|  | 3567 | if (instruction->IsDiv()) { | 
|  | 3568 | DCHECK_EQ(EAX, out); | 
|  | 3569 | } else { | 
|  | 3570 | DCHECK_EQ(EDX, out); | 
|  | 3571 | } | 
|  | 3572 |  | 
|  | 3573 | int64_t magic; | 
|  | 3574 | int shift; | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 3575 | CalculateMagicAndShiftForDivRem(imm, /* is_long= */ false, &magic, &shift); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3576 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3577 | // Save the numerator. | 
|  | 3578 | __ movl(num, eax); | 
|  | 3579 |  | 
|  | 3580 | // EAX = magic | 
|  | 3581 | __ movl(eax, Immediate(magic)); | 
|  | 3582 |  | 
|  | 3583 | // EDX:EAX = magic * numerator | 
|  | 3584 | __ imull(num); | 
|  | 3585 |  | 
|  | 3586 | if (imm > 0 && magic < 0) { | 
|  | 3587 | // EDX += num | 
|  | 3588 | __ addl(edx, num); | 
|  | 3589 | } else if (imm < 0 && magic > 0) { | 
|  | 3590 | __ subl(edx, num); | 
|  | 3591 | } | 
|  | 3592 |  | 
|  | 3593 | // Shift if needed. | 
|  | 3594 | if (shift != 0) { | 
|  | 3595 | __ sarl(edx, Immediate(shift)); | 
|  | 3596 | } | 
|  | 3597 |  | 
|  | 3598 | // EDX += 1 if EDX < 0 | 
|  | 3599 | __ movl(eax, edx); | 
|  | 3600 | __ shrl(edx, Immediate(31)); | 
|  | 3601 | __ addl(edx, eax); | 
|  | 3602 |  | 
|  | 3603 | if (instruction->IsRem()) { | 
|  | 3604 | __ movl(eax, num); | 
|  | 3605 | __ imull(edx, Immediate(imm)); | 
|  | 3606 | __ subl(eax, edx); | 
|  | 3607 | __ movl(edx, eax); | 
|  | 3608 | } else { | 
|  | 3609 | __ movl(eax, edx); | 
|  | 3610 | } | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3611 | } | 
|  | 3612 |  | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3613 | void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) { | 
|  | 3614 | DCHECK(instruction->IsDiv() || instruction->IsRem()); | 
|  | 3615 |  | 
|  | 3616 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 3617 | Location out = locations->Out(); | 
|  | 3618 | Location first = locations->InAt(0); | 
|  | 3619 | Location second = locations->InAt(1); | 
|  | 3620 | bool is_div = instruction->IsDiv(); | 
|  | 3621 |  | 
|  | 3622 | switch (instruction->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3623 | case DataType::Type::kInt32: { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 3624 | DCHECK_EQ(EAX, first.AsRegister<Register>()); | 
|  | 3625 | DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>()); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3626 |  | 
| Vladimir Marko | 13c86fd | 2015-11-11 12:37:46 +0000 | [diff] [blame] | 3627 | if (second.IsConstant()) { | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3628 | int32_t imm = second.GetConstant()->AsIntConstant()->GetValue(); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3629 |  | 
|  | 3630 | if (imm == 0) { | 
|  | 3631 | // Do not generate anything for 0. DivZeroCheck would forbid any generated code. | 
|  | 3632 | } else if (imm == 1 || imm == -1) { | 
|  | 3633 | DivRemOneOrMinusOne(instruction); | 
| Shalini Salomi Bodapati | a66784b | 2018-11-06 13:05:44 +0530 | [diff] [blame] | 3634 | } else if (IsPowerOfTwo(AbsOrMin(imm))) { | 
|  | 3635 | if (is_div) { | 
|  | 3636 | DivByPowerOfTwo(instruction->AsDiv()); | 
|  | 3637 | } else { | 
|  | 3638 | RemByPowerOfTwo(instruction->AsRem()); | 
|  | 3639 | } | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3640 | } else { | 
|  | 3641 | DCHECK(imm <= -2 || imm >= 2); | 
|  | 3642 | GenerateDivRemWithAnyConstant(instruction); | 
|  | 3643 | } | 
|  | 3644 | } else { | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 3645 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) DivRemMinusOneSlowPathX86( | 
| David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 3646 | instruction, out.AsRegister<Register>(), is_div); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3647 | codegen_->AddSlowPath(slow_path); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3648 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3649 | Register second_reg = second.AsRegister<Register>(); | 
|  | 3650 | // 0x80000000/-1 triggers an arithmetic exception! | 
|  | 3651 | // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so | 
|  | 3652 | // it's safe to just use negl instead of more complex comparisons. | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3653 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3654 | __ cmpl(second_reg, Immediate(-1)); | 
|  | 3655 | __ j(kEqual, slow_path->GetEntryLabel()); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3656 |  | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3657 | // edx:eax <- sign-extended of eax | 
|  | 3658 | __ cdq(); | 
|  | 3659 | // eax = quotient, edx = remainder | 
|  | 3660 | __ idivl(second_reg); | 
|  | 3661 | __ Bind(slow_path->GetExitLabel()); | 
|  | 3662 | } | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3663 | break; | 
|  | 3664 | } | 
|  | 3665 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3666 | case DataType::Type::kInt64: { | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3667 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3668 | DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>()); | 
|  | 3669 | DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>()); | 
|  | 3670 | DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>()); | 
|  | 3671 | DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>()); | 
|  | 3672 | DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>()); | 
|  | 3673 | DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>()); | 
|  | 3674 |  | 
|  | 3675 | if (is_div) { | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3676 | codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc()); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3677 | CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>(); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3678 | } else { | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 3679 | codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc()); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 3680 | CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>(); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3681 | } | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3682 | break; | 
|  | 3683 | } | 
|  | 3684 |  | 
|  | 3685 | default: | 
|  | 3686 | LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType(); | 
|  | 3687 | } | 
|  | 3688 | } | 
|  | 3689 |  | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3690 | void LocationsBuilderX86::VisitDiv(HDiv* div) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3691 | LocationSummary::CallKind call_kind = (div->GetResultType() == DataType::Type::kInt64) | 
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3692 | ? LocationSummary::kCallOnMainOnly | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3693 | : LocationSummary::kNoCall; | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3694 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(div, call_kind); | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3695 |  | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3696 | switch (div->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3697 | case DataType::Type::kInt32: { | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3698 | locations->SetInAt(0, Location::RegisterLocation(EAX)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3699 | locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1))); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3700 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3701 | // Intel uses edx:eax as the dividend. | 
|  | 3702 | locations->AddTemp(Location::RegisterLocation(EDX)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3703 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way | 
|  | 3704 | // which enforces results to be in EAX and EDX, things are simpler if we use EAX also as | 
|  | 3705 | // output and request another temp. | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3706 | if (div->InputAt(1)->IsIntConstant()) { | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3707 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 3708 | } | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3709 | break; | 
|  | 3710 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3711 | case DataType::Type::kInt64: { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 3712 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3713 | locations->SetInAt(0, Location::RegisterPairLocation( | 
|  | 3714 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); | 
|  | 3715 | locations->SetInAt(1, Location::RegisterPairLocation( | 
|  | 3716 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); | 
|  | 3717 | // Runtime helper puts the result in EAX, EDX. | 
|  | 3718 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3719 | break; | 
|  | 3720 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3721 | case DataType::Type::kFloat32: | 
|  | 3722 | case DataType::Type::kFloat64: { | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3723 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3724 | if (div->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3725 | DCHECK(div->InputAt(1)->IsEmittedAtUseSite()); | 
| Nicolas Geoffray | 7770a3e | 2016-02-03 10:13:41 +0000 | [diff] [blame] | 3726 | } else if (div->InputAt(1)->IsConstant()) { | 
|  | 3727 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3728 | } else { | 
|  | 3729 | locations->SetInAt(1, Location::Any()); | 
|  | 3730 | } | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3731 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3732 | break; | 
|  | 3733 | } | 
|  | 3734 |  | 
|  | 3735 | default: | 
|  | 3736 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); | 
|  | 3737 | } | 
|  | 3738 | } | 
|  | 3739 |  | 
|  | 3740 | void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) { | 
|  | 3741 | LocationSummary* locations = div->GetLocations(); | 
|  | 3742 | Location first = locations->InAt(0); | 
|  | 3743 | Location second = locations->InAt(1); | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3744 |  | 
|  | 3745 | switch (div->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3746 | case DataType::Type::kInt32: | 
|  | 3747 | case DataType::Type::kInt64: { | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3748 | GenerateDivRemIntegral(div); | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3749 | break; | 
|  | 3750 | } | 
|  | 3751 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3752 | case DataType::Type::kFloat32: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3753 | if (second.IsFpuRegister()) { | 
|  | 3754 | __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
|  | 3755 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3756 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3757 | DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3758 | __ divss(first.AsFpuRegister<XmmRegister>(), | 
|  | 3759 | codegen_->LiteralFloatAddress( | 
|  | 3760 | const_area->GetConstant()->AsFloatConstant()->GetValue(), | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3761 | const_area->GetBaseMethodAddress(), | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3762 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
|  | 3763 | } else { | 
|  | 3764 | DCHECK(second.IsStackSlot()); | 
|  | 3765 | __ divss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
|  | 3766 | } | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3767 | break; | 
|  | 3768 | } | 
|  | 3769 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3770 | case DataType::Type::kFloat64: { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3771 | if (second.IsFpuRegister()) { | 
|  | 3772 | __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>()); | 
|  | 3773 | } else if (div->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 3774 | HX86LoadFromConstantTable* const_area = div->InputAt(1)->AsX86LoadFromConstantTable(); | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 3775 | DCHECK(const_area->IsEmittedAtUseSite()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3776 | __ divsd(first.AsFpuRegister<XmmRegister>(), | 
|  | 3777 | codegen_->LiteralDoubleAddress( | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 3778 | const_area->GetConstant()->AsDoubleConstant()->GetValue(), | 
|  | 3779 | const_area->GetBaseMethodAddress(), | 
|  | 3780 | const_area->GetLocations()->InAt(0).AsRegister<Register>())); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 3781 | } else { | 
|  | 3782 | DCHECK(second.IsDoubleStackSlot()); | 
|  | 3783 | __ divsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex())); | 
|  | 3784 | } | 
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3785 | break; | 
|  | 3786 | } | 
|  | 3787 |  | 
|  | 3788 | default: | 
|  | 3789 | LOG(FATAL) << "Unexpected div type " << div->GetResultType(); | 
|  | 3790 | } | 
|  | 3791 | } | 
|  | 3792 |  | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3793 | void LocationsBuilderX86::VisitRem(HRem* rem) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3794 | DataType::Type type = rem->GetResultType(); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3795 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3796 | LocationSummary::CallKind call_kind = (rem->GetResultType() == DataType::Type::kInt64) | 
| Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 3797 | ? LocationSummary::kCallOnMainOnly | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 3798 | : LocationSummary::kNoCall; | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3799 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(rem, call_kind); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3800 |  | 
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3801 | switch (type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3802 | case DataType::Type::kInt32: { | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3803 | locations->SetInAt(0, Location::RegisterLocation(EAX)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3804 | locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1))); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3805 | locations->SetOut(Location::RegisterLocation(EDX)); | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3806 | // We need to save the numerator while we tweak eax and edx. As we are using imul in a way | 
|  | 3807 | // which enforces results to be in EAX and EDX, things are simpler if we use EDX also as | 
|  | 3808 | // output and request another temp. | 
| Guillaume Sanchez | b19930c | 2015-04-09 21:12:15 +0100 | [diff] [blame] | 3809 | if (rem->InputAt(1)->IsIntConstant()) { | 
| Guillaume Sanchez | 0f88e87 | 2015-03-30 17:55:45 +0100 | [diff] [blame] | 3810 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 3811 | } | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3812 | break; | 
|  | 3813 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3814 | case DataType::Type::kInt64: { | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3815 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 3816 | locations->SetInAt(0, Location::RegisterPairLocation( | 
|  | 3817 | calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1))); | 
|  | 3818 | locations->SetInAt(1, Location::RegisterPairLocation( | 
|  | 3819 | calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3))); | 
|  | 3820 | // Runtime helper puts the result in EAX, EDX. | 
|  | 3821 | locations->SetOut(Location::RegisterPairLocation(EAX, EDX)); | 
|  | 3822 | break; | 
|  | 3823 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3824 | case DataType::Type::kFloat64: | 
|  | 3825 | case DataType::Type::kFloat32: { | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3826 | locations->SetInAt(0, Location::Any()); | 
|  | 3827 | locations->SetInAt(1, Location::Any()); | 
|  | 3828 | locations->SetOut(Location::RequiresFpuRegister()); | 
|  | 3829 | locations->AddTemp(Location::RegisterLocation(EAX)); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3830 | break; | 
|  | 3831 | } | 
|  | 3832 |  | 
|  | 3833 | default: | 
| Calin Juravle | d2ec87d | 2014-12-08 14:24:46 +0000 | [diff] [blame] | 3834 | LOG(FATAL) << "Unexpected rem type " << type; | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3835 | } | 
|  | 3836 | } | 
|  | 3837 |  | 
|  | 3838 | void InstructionCodeGeneratorX86::VisitRem(HRem* rem) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3839 | DataType::Type type = rem->GetResultType(); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3840 | switch (type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3841 | case DataType::Type::kInt32: | 
|  | 3842 | case DataType::Type::kInt64: { | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3843 | GenerateDivRemIntegral(rem); | 
|  | 3844 | break; | 
|  | 3845 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3846 | case DataType::Type::kFloat32: | 
|  | 3847 | case DataType::Type::kFloat64: { | 
| Mark Mendell | 24f2dfa | 2015-01-14 19:51:45 -0500 | [diff] [blame] | 3848 | GenerateRemFP(rem); | 
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3849 | break; | 
|  | 3850 | } | 
|  | 3851 | default: | 
|  | 3852 | LOG(FATAL) << "Unexpected rem type " << type; | 
|  | 3853 | } | 
|  | 3854 | } | 
|  | 3855 |  | 
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3856 | static void CreateMinMaxLocations(ArenaAllocator* allocator, HBinaryOperation* minmax) { | 
|  | 3857 | LocationSummary* locations = new (allocator) LocationSummary(minmax); | 
|  | 3858 | switch (minmax->GetResultType()) { | 
|  | 3859 | case DataType::Type::kInt32: | 
|  | 3860 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3861 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 3862 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3863 | break; | 
|  | 3864 | case DataType::Type::kInt64: | 
|  | 3865 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 3866 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 3867 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3868 | // Register to use to perform a long subtract to set cc. | 
|  | 3869 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 3870 | break; | 
|  | 3871 | case DataType::Type::kFloat32: | 
|  | 3872 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 3873 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 3874 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3875 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 3876 | break; | 
|  | 3877 | case DataType::Type::kFloat64: | 
|  | 3878 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 3879 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 3880 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 3881 | break; | 
|  | 3882 | default: | 
|  | 3883 | LOG(FATAL) << "Unexpected type for HMinMax " << minmax->GetResultType(); | 
|  | 3884 | } | 
|  | 3885 | } | 
|  | 3886 |  | 
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 3887 | void InstructionCodeGeneratorX86::GenerateMinMaxInt(LocationSummary* locations, | 
|  | 3888 | bool is_min, | 
|  | 3889 | DataType::Type type) { | 
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 3890 | Location op1_loc = locations->InAt(0); | 
|  | 3891 | Location op2_loc = locations->InAt(1); | 
|  | 3892 |  | 
|  | 3893 | // Shortcut for same input locations. | 
|  | 3894 | if (op1_loc.Equals(op2_loc)) { | 
|  | 3895 | // Can return immediately, as op1_loc == out_loc. | 
|  | 3896 | // Note: if we ever support separate registers, e.g., output into memory, we need to check for | 
|  | 3897 | //       a copy here. | 
|  | 3898 | DCHECK(locations->Out().Equals(op1_loc)); | 
|  | 3899 | return; | 
|  | 3900 | } | 
|  | 3901 |  | 
|  | 3902 | if (type == DataType::Type::kInt64) { | 
|  | 3903 | // Need to perform a subtract to get the sign right. | 
|  | 3904 | // op1 is already in the same location as the output. | 
|  | 3905 | Location output = locations->Out(); | 
|  | 3906 | Register output_lo = output.AsRegisterPairLow<Register>(); | 
|  | 3907 | Register output_hi = output.AsRegisterPairHigh<Register>(); | 
|  | 3908 |  | 
|  | 3909 | Register op2_lo = op2_loc.AsRegisterPairLow<Register>(); | 
|  | 3910 | Register op2_hi = op2_loc.AsRegisterPairHigh<Register>(); | 
|  | 3911 |  | 
|  | 3912 | // The comparison is performed by subtracting the second operand from | 
|  | 3913 | // the first operand and then setting the status flags in the same | 
|  | 3914 | // manner as the SUB instruction." | 
|  | 3915 | __ cmpl(output_lo, op2_lo); | 
|  | 3916 |  | 
|  | 3917 | // Now use a temp and the borrow to finish the subtraction of op2_hi. | 
|  | 3918 | Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 3919 | __ movl(temp, output_hi); | 
|  | 3920 | __ sbbl(temp, op2_hi); | 
|  | 3921 |  | 
|  | 3922 | // Now the condition code is correct. | 
|  | 3923 | Condition cond = is_min ? Condition::kGreaterEqual : Condition::kLess; | 
|  | 3924 | __ cmovl(cond, output_lo, op2_lo); | 
|  | 3925 | __ cmovl(cond, output_hi, op2_hi); | 
|  | 3926 | } else { | 
|  | 3927 | DCHECK_EQ(type, DataType::Type::kInt32); | 
|  | 3928 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 3929 | Register op2 = op2_loc.AsRegister<Register>(); | 
|  | 3930 |  | 
|  | 3931 | //  (out := op1) | 
|  | 3932 | //  out <=? op2 | 
|  | 3933 | //  if out is min jmp done | 
|  | 3934 | //  out := op2 | 
|  | 3935 | // done: | 
|  | 3936 |  | 
|  | 3937 | __ cmpl(out, op2); | 
|  | 3938 | Condition cond = is_min ? Condition::kGreater : Condition::kLess; | 
|  | 3939 | __ cmovl(cond, out, op2); | 
|  | 3940 | } | 
|  | 3941 | } | 
|  | 3942 |  | 
|  | 3943 | void InstructionCodeGeneratorX86::GenerateMinMaxFP(LocationSummary* locations, | 
|  | 3944 | bool is_min, | 
|  | 3945 | DataType::Type type) { | 
|  | 3946 | Location op1_loc = locations->InAt(0); | 
|  | 3947 | Location op2_loc = locations->InAt(1); | 
|  | 3948 | Location out_loc = locations->Out(); | 
|  | 3949 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); | 
|  | 3950 |  | 
|  | 3951 | // Shortcut for same input locations. | 
|  | 3952 | if (op1_loc.Equals(op2_loc)) { | 
|  | 3953 | DCHECK(out_loc.Equals(op1_loc)); | 
|  | 3954 | return; | 
|  | 3955 | } | 
|  | 3956 |  | 
|  | 3957 | //  (out := op1) | 
|  | 3958 | //  out <=? op2 | 
|  | 3959 | //  if Nan jmp Nan_label | 
|  | 3960 | //  if out is min jmp done | 
|  | 3961 | //  if op2 is min jmp op2_label | 
|  | 3962 | //  handle -0/+0 | 
|  | 3963 | //  jmp done | 
|  | 3964 | // Nan_label: | 
|  | 3965 | //  out := NaN | 
|  | 3966 | // op2_label: | 
|  | 3967 | //  out := op2 | 
|  | 3968 | // done: | 
|  | 3969 | // | 
|  | 3970 | // This removes one jmp, but needs to copy one input (op1) to out. | 
|  | 3971 | // | 
|  | 3972 | // TODO: This is straight from Quick (except literal pool). Make NaN an out-of-line slowpath? | 
|  | 3973 |  | 
|  | 3974 | XmmRegister op2 = op2_loc.AsFpuRegister<XmmRegister>(); | 
|  | 3975 |  | 
|  | 3976 | NearLabel nan, done, op2_label; | 
|  | 3977 | if (type == DataType::Type::kFloat64) { | 
|  | 3978 | __ ucomisd(out, op2); | 
|  | 3979 | } else { | 
|  | 3980 | DCHECK_EQ(type, DataType::Type::kFloat32); | 
|  | 3981 | __ ucomiss(out, op2); | 
|  | 3982 | } | 
|  | 3983 |  | 
|  | 3984 | __ j(Condition::kParityEven, &nan); | 
|  | 3985 |  | 
|  | 3986 | __ j(is_min ? Condition::kAbove : Condition::kBelow, &op2_label); | 
|  | 3987 | __ j(is_min ? Condition::kBelow : Condition::kAbove, &done); | 
|  | 3988 |  | 
|  | 3989 | // Handle 0.0/-0.0. | 
|  | 3990 | if (is_min) { | 
|  | 3991 | if (type == DataType::Type::kFloat64) { | 
|  | 3992 | __ orpd(out, op2); | 
|  | 3993 | } else { | 
|  | 3994 | __ orps(out, op2); | 
|  | 3995 | } | 
|  | 3996 | } else { | 
|  | 3997 | if (type == DataType::Type::kFloat64) { | 
|  | 3998 | __ andpd(out, op2); | 
|  | 3999 | } else { | 
|  | 4000 | __ andps(out, op2); | 
|  | 4001 | } | 
|  | 4002 | } | 
|  | 4003 | __ jmp(&done); | 
|  | 4004 |  | 
|  | 4005 | // NaN handling. | 
|  | 4006 | __ Bind(&nan); | 
|  | 4007 | if (type == DataType::Type::kFloat64) { | 
|  | 4008 | // TODO: Use a constant from the constant table (requires extra input). | 
|  | 4009 | __ LoadLongConstant(out, kDoubleNaN); | 
|  | 4010 | } else { | 
|  | 4011 | Register constant = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 4012 | __ movl(constant, Immediate(kFloatNaN)); | 
|  | 4013 | __ movd(out, constant); | 
|  | 4014 | } | 
|  | 4015 | __ jmp(&done); | 
|  | 4016 |  | 
|  | 4017 | // out := op2; | 
|  | 4018 | __ Bind(&op2_label); | 
|  | 4019 | if (type == DataType::Type::kFloat64) { | 
|  | 4020 | __ movsd(out, op2); | 
|  | 4021 | } else { | 
|  | 4022 | __ movss(out, op2); | 
|  | 4023 | } | 
|  | 4024 |  | 
|  | 4025 | // Done. | 
|  | 4026 | __ Bind(&done); | 
|  | 4027 | } | 
|  | 4028 |  | 
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4029 | void InstructionCodeGeneratorX86::GenerateMinMax(HBinaryOperation* minmax, bool is_min) { | 
|  | 4030 | DataType::Type type = minmax->GetResultType(); | 
|  | 4031 | switch (type) { | 
|  | 4032 | case DataType::Type::kInt32: | 
|  | 4033 | case DataType::Type::kInt64: | 
|  | 4034 | GenerateMinMaxInt(minmax->GetLocations(), is_min, type); | 
|  | 4035 | break; | 
|  | 4036 | case DataType::Type::kFloat32: | 
|  | 4037 | case DataType::Type::kFloat64: | 
|  | 4038 | GenerateMinMaxFP(minmax->GetLocations(), is_min, type); | 
|  | 4039 | break; | 
|  | 4040 | default: | 
|  | 4041 | LOG(FATAL) << "Unexpected type for HMinMax " << type; | 
|  | 4042 | } | 
|  | 4043 | } | 
|  | 4044 |  | 
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4045 | void LocationsBuilderX86::VisitMin(HMin* min) { | 
|  | 4046 | CreateMinMaxLocations(GetGraph()->GetAllocator(), min); | 
|  | 4047 | } | 
|  | 4048 |  | 
|  | 4049 | void InstructionCodeGeneratorX86::VisitMin(HMin* min) { | 
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4050 | GenerateMinMax(min, /*is_min*/ true); | 
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4051 | } | 
|  | 4052 |  | 
|  | 4053 | void LocationsBuilderX86::VisitMax(HMax* max) { | 
|  | 4054 | CreateMinMaxLocations(GetGraph()->GetAllocator(), max); | 
|  | 4055 | } | 
|  | 4056 |  | 
|  | 4057 | void InstructionCodeGeneratorX86::VisitMax(HMax* max) { | 
| Aart Bik | 351df3e | 2018-03-07 11:54:57 -0800 | [diff] [blame] | 4058 | GenerateMinMax(max, /*is_min*/ false); | 
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 4059 | } | 
|  | 4060 |  | 
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 4061 | void LocationsBuilderX86::VisitAbs(HAbs* abs) { | 
|  | 4062 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(abs); | 
|  | 4063 | switch (abs->GetResultType()) { | 
|  | 4064 | case DataType::Type::kInt32: | 
|  | 4065 | locations->SetInAt(0, Location::RegisterLocation(EAX)); | 
|  | 4066 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 4067 | locations->AddTemp(Location::RegisterLocation(EDX)); | 
|  | 4068 | break; | 
|  | 4069 | case DataType::Type::kInt64: | 
|  | 4070 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4071 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); | 
|  | 4072 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 4073 | break; | 
|  | 4074 | case DataType::Type::kFloat32: | 
|  | 4075 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 4076 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 4077 | locations->AddTemp(Location::RequiresFpuRegister()); | 
|  | 4078 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 4079 | break; | 
|  | 4080 | case DataType::Type::kFloat64: | 
|  | 4081 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
|  | 4082 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 4083 | locations->AddTemp(Location::RequiresFpuRegister()); | 
|  | 4084 | break; | 
|  | 4085 | default: | 
|  | 4086 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); | 
|  | 4087 | } | 
|  | 4088 | } | 
|  | 4089 |  | 
|  | 4090 | void InstructionCodeGeneratorX86::VisitAbs(HAbs* abs) { | 
|  | 4091 | LocationSummary* locations = abs->GetLocations(); | 
|  | 4092 | switch (abs->GetResultType()) { | 
|  | 4093 | case DataType::Type::kInt32: { | 
|  | 4094 | Register out = locations->Out().AsRegister<Register>(); | 
|  | 4095 | DCHECK_EQ(out, EAX); | 
|  | 4096 | Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 4097 | DCHECK_EQ(temp, EDX); | 
|  | 4098 | // Sign extend EAX into EDX. | 
|  | 4099 | __ cdq(); | 
|  | 4100 | // XOR EAX with sign. | 
|  | 4101 | __ xorl(EAX, EDX); | 
|  | 4102 | // Subtract out sign to correct. | 
|  | 4103 | __ subl(EAX, EDX); | 
|  | 4104 | // The result is in EAX. | 
|  | 4105 | break; | 
|  | 4106 | } | 
|  | 4107 | case DataType::Type::kInt64: { | 
|  | 4108 | Location input = locations->InAt(0); | 
|  | 4109 | Register input_lo = input.AsRegisterPairLow<Register>(); | 
|  | 4110 | Register input_hi = input.AsRegisterPairHigh<Register>(); | 
|  | 4111 | Location output = locations->Out(); | 
|  | 4112 | Register output_lo = output.AsRegisterPairLow<Register>(); | 
|  | 4113 | Register output_hi = output.AsRegisterPairHigh<Register>(); | 
|  | 4114 | Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 4115 | // Compute the sign into the temporary. | 
|  | 4116 | __ movl(temp, input_hi); | 
|  | 4117 | __ sarl(temp, Immediate(31)); | 
|  | 4118 | // Store the sign into the output. | 
|  | 4119 | __ movl(output_lo, temp); | 
|  | 4120 | __ movl(output_hi, temp); | 
|  | 4121 | // XOR the input to the output. | 
|  | 4122 | __ xorl(output_lo, input_lo); | 
|  | 4123 | __ xorl(output_hi, input_hi); | 
|  | 4124 | // Subtract the sign. | 
|  | 4125 | __ subl(output_lo, temp); | 
|  | 4126 | __ sbbl(output_hi, temp); | 
|  | 4127 | break; | 
|  | 4128 | } | 
|  | 4129 | case DataType::Type::kFloat32: { | 
|  | 4130 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); | 
|  | 4131 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
|  | 4132 | Register constant = locations->GetTemp(1).AsRegister<Register>(); | 
|  | 4133 | __ movl(constant, Immediate(INT32_C(0x7FFFFFFF))); | 
|  | 4134 | __ movd(temp, constant); | 
|  | 4135 | __ andps(out, temp); | 
|  | 4136 | break; | 
|  | 4137 | } | 
|  | 4138 | case DataType::Type::kFloat64: { | 
|  | 4139 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); | 
|  | 4140 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
|  | 4141 | // TODO: Use a constant from the constant table (requires extra input). | 
|  | 4142 | __ LoadLongConstant(temp, INT64_C(0x7FFFFFFFFFFFFFFF)); | 
|  | 4143 | __ andpd(out, temp); | 
|  | 4144 | break; | 
|  | 4145 | } | 
|  | 4146 | default: | 
|  | 4147 | LOG(FATAL) << "Unexpected type for HAbs " << abs->GetResultType(); | 
|  | 4148 | } | 
|  | 4149 | } | 
|  | 4150 |  | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4151 | void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 4152 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4153 | switch (instruction->GetType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4154 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4155 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4156 | case DataType::Type::kInt8: | 
|  | 4157 | case DataType::Type::kUint16: | 
|  | 4158 | case DataType::Type::kInt16: | 
|  | 4159 | case DataType::Type::kInt32: { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4160 | locations->SetInAt(0, Location::Any()); | 
|  | 4161 | break; | 
|  | 4162 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4163 | case DataType::Type::kInt64: { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4164 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); | 
|  | 4165 | if (!instruction->IsConstant()) { | 
|  | 4166 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 4167 | } | 
|  | 4168 | break; | 
|  | 4169 | } | 
|  | 4170 | default: | 
|  | 4171 | LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType(); | 
|  | 4172 | } | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4173 | } | 
|  | 4174 |  | 
|  | 4175 | void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) { | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 4176 | SlowPathCode* slow_path = | 
|  | 4177 | new (codegen_->GetScopedAllocator()) DivZeroCheckSlowPathX86(instruction); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4178 | codegen_->AddSlowPath(slow_path); | 
|  | 4179 |  | 
|  | 4180 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 4181 | Location value = locations->InAt(0); | 
|  | 4182 |  | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4183 | switch (instruction->GetType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4184 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4185 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4186 | case DataType::Type::kInt8: | 
|  | 4187 | case DataType::Type::kUint16: | 
|  | 4188 | case DataType::Type::kInt16: | 
|  | 4189 | case DataType::Type::kInt32: { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4190 | if (value.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4191 | __ testl(value.AsRegister<Register>(), value.AsRegister<Register>()); | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4192 | __ j(kEqual, slow_path->GetEntryLabel()); | 
|  | 4193 | } else if (value.IsStackSlot()) { | 
|  | 4194 | __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0)); | 
|  | 4195 | __ j(kEqual, slow_path->GetEntryLabel()); | 
|  | 4196 | } else { | 
|  | 4197 | DCHECK(value.IsConstant()) << value; | 
|  | 4198 | if (value.GetConstant()->AsIntConstant()->GetValue() == 0) { | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 4199 | __ jmp(slow_path->GetEntryLabel()); | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4200 | } | 
|  | 4201 | } | 
|  | 4202 | break; | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4203 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4204 | case DataType::Type::kInt64: { | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4205 | if (value.IsRegisterPair()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4206 | Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
| Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 4207 | __ movl(temp, value.AsRegisterPairLow<Register>()); | 
|  | 4208 | __ orl(temp, value.AsRegisterPairHigh<Register>()); | 
|  | 4209 | __ j(kEqual, slow_path->GetEntryLabel()); | 
|  | 4210 | } else { | 
|  | 4211 | DCHECK(value.IsConstant()) << value; | 
|  | 4212 | if (value.GetConstant()->AsLongConstant()->GetValue() == 0) { | 
|  | 4213 | __ jmp(slow_path->GetEntryLabel()); | 
|  | 4214 | } | 
|  | 4215 | } | 
|  | 4216 | break; | 
|  | 4217 | } | 
|  | 4218 | default: | 
|  | 4219 | LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType(); | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4220 | } | 
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4221 | } | 
|  | 4222 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4223 | void LocationsBuilderX86::HandleShift(HBinaryOperation* op) { | 
|  | 4224 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); | 
|  | 4225 |  | 
|  | 4226 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4227 | new (GetGraph()->GetAllocator()) LocationSummary(op, LocationSummary::kNoCall); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4228 |  | 
|  | 4229 | switch (op->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4230 | case DataType::Type::kInt32: | 
|  | 4231 | case DataType::Type::kInt64: { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4232 | // Can't have Location::Any() and output SameAsFirstInput() | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4233 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4234 | // The shift count needs to be in CL or a constant. | 
|  | 4235 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1))); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4236 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 4237 | break; | 
|  | 4238 | } | 
|  | 4239 | default: | 
|  | 4240 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); | 
|  | 4241 | } | 
|  | 4242 | } | 
|  | 4243 |  | 
|  | 4244 | void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) { | 
|  | 4245 | DCHECK(op->IsShl() || op->IsShr() || op->IsUShr()); | 
|  | 4246 |  | 
|  | 4247 | LocationSummary* locations = op->GetLocations(); | 
|  | 4248 | Location first = locations->InAt(0); | 
|  | 4249 | Location second = locations->InAt(1); | 
|  | 4250 | DCHECK(first.Equals(locations->Out())); | 
|  | 4251 |  | 
|  | 4252 | switch (op->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4253 | case DataType::Type::kInt32: { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4254 | DCHECK(first.IsRegister()); | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4255 | Register first_reg = first.AsRegister<Register>(); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4256 | if (second.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4257 | Register second_reg = second.AsRegister<Register>(); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4258 | DCHECK_EQ(ECX, second_reg); | 
|  | 4259 | if (op->IsShl()) { | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4260 | __ shll(first_reg, second_reg); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4261 | } else if (op->IsShr()) { | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4262 | __ sarl(first_reg, second_reg); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4263 | } else { | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4264 | __ shrl(first_reg, second_reg); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4265 | } | 
|  | 4266 | } else { | 
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4267 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance; | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4268 | if (shift == 0) { | 
|  | 4269 | return; | 
|  | 4270 | } | 
|  | 4271 | Immediate imm(shift); | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4272 | if (op->IsShl()) { | 
|  | 4273 | __ shll(first_reg, imm); | 
|  | 4274 | } else if (op->IsShr()) { | 
|  | 4275 | __ sarl(first_reg, imm); | 
|  | 4276 | } else { | 
|  | 4277 | __ shrl(first_reg, imm); | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4278 | } | 
|  | 4279 | } | 
|  | 4280 | break; | 
|  | 4281 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4282 | case DataType::Type::kInt64: { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4283 | if (second.IsRegister()) { | 
|  | 4284 | Register second_reg = second.AsRegister<Register>(); | 
|  | 4285 | DCHECK_EQ(ECX, second_reg); | 
|  | 4286 | if (op->IsShl()) { | 
|  | 4287 | GenerateShlLong(first, second_reg); | 
|  | 4288 | } else if (op->IsShr()) { | 
|  | 4289 | GenerateShrLong(first, second_reg); | 
|  | 4290 | } else { | 
|  | 4291 | GenerateUShrLong(first, second_reg); | 
|  | 4292 | } | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4293 | } else { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4294 | // Shift by a constant. | 
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4295 | int32_t shift = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4296 | // Nothing to do if the shift is 0, as the input is already the output. | 
|  | 4297 | if (shift != 0) { | 
|  | 4298 | if (op->IsShl()) { | 
|  | 4299 | GenerateShlLong(first, shift); | 
|  | 4300 | } else if (op->IsShr()) { | 
|  | 4301 | GenerateShrLong(first, shift); | 
|  | 4302 | } else { | 
|  | 4303 | GenerateUShrLong(first, shift); | 
|  | 4304 | } | 
|  | 4305 | } | 
| Roland Levillain | f9aac1e | 2015-04-10 18:12:48 +0000 | [diff] [blame] | 4306 | } | 
|  | 4307 | break; | 
|  | 4308 | } | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4309 | default: | 
|  | 4310 | LOG(FATAL) << "Unexpected op type " << op->GetResultType(); | 
|  | 4311 | } | 
|  | 4312 | } | 
|  | 4313 |  | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4314 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, int shift) { | 
|  | 4315 | Register low = loc.AsRegisterPairLow<Register>(); | 
|  | 4316 | Register high = loc.AsRegisterPairHigh<Register>(); | 
| Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 4317 | if (shift == 1) { | 
|  | 4318 | // This is just an addition. | 
|  | 4319 | __ addl(low, low); | 
|  | 4320 | __ adcl(high, high); | 
|  | 4321 | } else if (shift == 32) { | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4322 | // Shift by 32 is easy. High gets low, and low gets 0. | 
|  | 4323 | codegen_->EmitParallelMoves( | 
|  | 4324 | loc.ToLow(), | 
|  | 4325 | loc.ToHigh(), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4326 | DataType::Type::kInt32, | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4327 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), | 
|  | 4328 | loc.ToLow(), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4329 | DataType::Type::kInt32); | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4330 | } else if (shift > 32) { | 
|  | 4331 | // Low part becomes 0.  High part is low part << (shift-32). | 
|  | 4332 | __ movl(high, low); | 
|  | 4333 | __ shll(high, Immediate(shift - 32)); | 
|  | 4334 | __ xorl(low, low); | 
|  | 4335 | } else { | 
|  | 4336 | // Between 1 and 31. | 
|  | 4337 | __ shld(high, low, Immediate(shift)); | 
|  | 4338 | __ shll(low, Immediate(shift)); | 
|  | 4339 | } | 
|  | 4340 | } | 
|  | 4341 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4342 | void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) { | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4343 | NearLabel done; | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4344 | __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter); | 
|  | 4345 | __ shll(loc.AsRegisterPairLow<Register>(), shifter); | 
|  | 4346 | __ testl(shifter, Immediate(32)); | 
|  | 4347 | __ j(kEqual, &done); | 
|  | 4348 | __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>()); | 
|  | 4349 | __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0)); | 
|  | 4350 | __ Bind(&done); | 
|  | 4351 | } | 
|  | 4352 |  | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4353 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, int shift) { | 
|  | 4354 | Register low = loc.AsRegisterPairLow<Register>(); | 
|  | 4355 | Register high = loc.AsRegisterPairHigh<Register>(); | 
|  | 4356 | if (shift == 32) { | 
|  | 4357 | // Need to copy the sign. | 
|  | 4358 | DCHECK_NE(low, high); | 
|  | 4359 | __ movl(low, high); | 
|  | 4360 | __ sarl(high, Immediate(31)); | 
|  | 4361 | } else if (shift > 32) { | 
|  | 4362 | DCHECK_NE(low, high); | 
|  | 4363 | // High part becomes sign. Low part is shifted by shift - 32. | 
|  | 4364 | __ movl(low, high); | 
|  | 4365 | __ sarl(high, Immediate(31)); | 
|  | 4366 | __ sarl(low, Immediate(shift - 32)); | 
|  | 4367 | } else { | 
|  | 4368 | // Between 1 and 31. | 
|  | 4369 | __ shrd(low, high, Immediate(shift)); | 
|  | 4370 | __ sarl(high, Immediate(shift)); | 
|  | 4371 | } | 
|  | 4372 | } | 
|  | 4373 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4374 | void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) { | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4375 | NearLabel done; | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4376 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); | 
|  | 4377 | __ sarl(loc.AsRegisterPairHigh<Register>(), shifter); | 
|  | 4378 | __ testl(shifter, Immediate(32)); | 
|  | 4379 | __ j(kEqual, &done); | 
|  | 4380 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); | 
|  | 4381 | __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31)); | 
|  | 4382 | __ Bind(&done); | 
|  | 4383 | } | 
|  | 4384 |  | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4385 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, int shift) { | 
|  | 4386 | Register low = loc.AsRegisterPairLow<Register>(); | 
|  | 4387 | Register high = loc.AsRegisterPairHigh<Register>(); | 
|  | 4388 | if (shift == 32) { | 
|  | 4389 | // Shift by 32 is easy. Low gets high, and high gets 0. | 
|  | 4390 | codegen_->EmitParallelMoves( | 
|  | 4391 | loc.ToHigh(), | 
|  | 4392 | loc.ToLow(), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4393 | DataType::Type::kInt32, | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4394 | Location::ConstantLocation(GetGraph()->GetIntConstant(0)), | 
|  | 4395 | loc.ToHigh(), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4396 | DataType::Type::kInt32); | 
| Mark P Mendell | 7394569 | 2015-04-29 14:56:17 +0000 | [diff] [blame] | 4397 | } else if (shift > 32) { | 
|  | 4398 | // Low part is high >> (shift - 32). High part becomes 0. | 
|  | 4399 | __ movl(low, high); | 
|  | 4400 | __ shrl(low, Immediate(shift - 32)); | 
|  | 4401 | __ xorl(high, high); | 
|  | 4402 | } else { | 
|  | 4403 | // Between 1 and 31. | 
|  | 4404 | __ shrd(low, high, Immediate(shift)); | 
|  | 4405 | __ shrl(high, Immediate(shift)); | 
|  | 4406 | } | 
|  | 4407 | } | 
|  | 4408 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4409 | void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) { | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4410 | NearLabel done; | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4411 | __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter); | 
|  | 4412 | __ shrl(loc.AsRegisterPairHigh<Register>(), shifter); | 
|  | 4413 | __ testl(shifter, Immediate(32)); | 
|  | 4414 | __ j(kEqual, &done); | 
|  | 4415 | __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>()); | 
|  | 4416 | __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0)); | 
|  | 4417 | __ Bind(&done); | 
|  | 4418 | } | 
|  | 4419 |  | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4420 | void LocationsBuilderX86::VisitRor(HRor* ror) { | 
|  | 4421 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4422 | new (GetGraph()->GetAllocator()) LocationSummary(ror, LocationSummary::kNoCall); | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4423 |  | 
|  | 4424 | switch (ror->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4425 | case DataType::Type::kInt64: | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4426 | // Add the temporary needed. | 
|  | 4427 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 4428 | FALLTHROUGH_INTENDED; | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4429 | case DataType::Type::kInt32: | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4430 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4431 | // The shift count needs to be in CL (unless it is a constant). | 
|  | 4432 | locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, ror->InputAt(1))); | 
|  | 4433 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 4434 | break; | 
|  | 4435 | default: | 
|  | 4436 | LOG(FATAL) << "Unexpected operation type " << ror->GetResultType(); | 
|  | 4437 | UNREACHABLE(); | 
|  | 4438 | } | 
|  | 4439 | } | 
|  | 4440 |  | 
|  | 4441 | void InstructionCodeGeneratorX86::VisitRor(HRor* ror) { | 
|  | 4442 | LocationSummary* locations = ror->GetLocations(); | 
|  | 4443 | Location first = locations->InAt(0); | 
|  | 4444 | Location second = locations->InAt(1); | 
|  | 4445 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4446 | if (ror->GetResultType() == DataType::Type::kInt32) { | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4447 | Register first_reg = first.AsRegister<Register>(); | 
|  | 4448 | if (second.IsRegister()) { | 
|  | 4449 | Register second_reg = second.AsRegister<Register>(); | 
|  | 4450 | __ rorl(first_reg, second_reg); | 
|  | 4451 | } else { | 
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4452 | Immediate imm(second.GetConstant()->AsIntConstant()->GetValue() & kMaxIntShiftDistance); | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4453 | __ rorl(first_reg, imm); | 
|  | 4454 | } | 
|  | 4455 | return; | 
|  | 4456 | } | 
|  | 4457 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4458 | DCHECK_EQ(ror->GetResultType(), DataType::Type::kInt64); | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4459 | Register first_reg_lo = first.AsRegisterPairLow<Register>(); | 
|  | 4460 | Register first_reg_hi = first.AsRegisterPairHigh<Register>(); | 
|  | 4461 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 4462 | if (second.IsRegister()) { | 
|  | 4463 | Register second_reg = second.AsRegister<Register>(); | 
|  | 4464 | DCHECK_EQ(second_reg, ECX); | 
|  | 4465 | __ movl(temp_reg, first_reg_hi); | 
|  | 4466 | __ shrd(first_reg_hi, first_reg_lo, second_reg); | 
|  | 4467 | __ shrd(first_reg_lo, temp_reg, second_reg); | 
|  | 4468 | __ movl(temp_reg, first_reg_hi); | 
|  | 4469 | __ testl(second_reg, Immediate(32)); | 
|  | 4470 | __ cmovl(kNotEqual, first_reg_hi, first_reg_lo); | 
|  | 4471 | __ cmovl(kNotEqual, first_reg_lo, temp_reg); | 
|  | 4472 | } else { | 
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4473 | int32_t shift_amt = second.GetConstant()->AsIntConstant()->GetValue() & kMaxLongShiftDistance; | 
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4474 | if (shift_amt == 0) { | 
|  | 4475 | // Already fine. | 
|  | 4476 | return; | 
|  | 4477 | } | 
|  | 4478 | if (shift_amt == 32) { | 
|  | 4479 | // Just swap. | 
|  | 4480 | __ movl(temp_reg, first_reg_lo); | 
|  | 4481 | __ movl(first_reg_lo, first_reg_hi); | 
|  | 4482 | __ movl(first_reg_hi, temp_reg); | 
|  | 4483 | return; | 
|  | 4484 | } | 
|  | 4485 |  | 
|  | 4486 | Immediate imm(shift_amt); | 
|  | 4487 | // Save the constents of the low value. | 
|  | 4488 | __ movl(temp_reg, first_reg_lo); | 
|  | 4489 |  | 
|  | 4490 | // Shift right into low, feeding bits from high. | 
|  | 4491 | __ shrd(first_reg_lo, first_reg_hi, imm); | 
|  | 4492 |  | 
|  | 4493 | // Shift right into high, feeding bits from the original low. | 
|  | 4494 | __ shrd(first_reg_hi, temp_reg, imm); | 
|  | 4495 |  | 
|  | 4496 | // Swap if needed. | 
|  | 4497 | if (shift_amt > 32) { | 
|  | 4498 | __ movl(temp_reg, first_reg_lo); | 
|  | 4499 | __ movl(first_reg_lo, first_reg_hi); | 
|  | 4500 | __ movl(first_reg_hi, temp_reg); | 
|  | 4501 | } | 
|  | 4502 | } | 
|  | 4503 | } | 
|  | 4504 |  | 
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4505 | void LocationsBuilderX86::VisitShl(HShl* shl) { | 
|  | 4506 | HandleShift(shl); | 
|  | 4507 | } | 
|  | 4508 |  | 
|  | 4509 | void InstructionCodeGeneratorX86::VisitShl(HShl* shl) { | 
|  | 4510 | HandleShift(shl); | 
|  | 4511 | } | 
|  | 4512 |  | 
|  | 4513 | void LocationsBuilderX86::VisitShr(HShr* shr) { | 
|  | 4514 | HandleShift(shr); | 
|  | 4515 | } | 
|  | 4516 |  | 
|  | 4517 | void InstructionCodeGeneratorX86::VisitShr(HShr* shr) { | 
|  | 4518 | HandleShift(shr); | 
|  | 4519 | } | 
|  | 4520 |  | 
|  | 4521 | void LocationsBuilderX86::VisitUShr(HUShr* ushr) { | 
|  | 4522 | HandleShift(ushr); | 
|  | 4523 | } | 
|  | 4524 |  | 
|  | 4525 | void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) { | 
|  | 4526 | HandleShift(ushr); | 
|  | 4527 | } | 
|  | 4528 |  | 
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4529 | void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4530 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( | 
|  | 4531 | instruction, LocationSummary::kCallOnMainOnly); | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4532 | locations->SetOut(Location::RegisterLocation(EAX)); | 
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4533 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 4534 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4535 | } | 
|  | 4536 |  | 
|  | 4537 | void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) { | 
| Alex Light | d109e30 | 2018-06-27 10:25:41 -0700 | [diff] [blame] | 4538 | codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc()); | 
|  | 4539 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); | 
|  | 4540 | DCHECK(!codegen_->IsLeafMethod()); | 
| Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 4541 | } | 
|  | 4542 |  | 
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4543 | void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4544 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( | 
|  | 4545 | instruction, LocationSummary::kCallOnMainOnly); | 
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4546 | locations->SetOut(Location::RegisterLocation(EAX)); | 
|  | 4547 | InvokeRuntimeCallingConvention calling_convention; | 
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4548 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 4549 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4550 | } | 
|  | 4551 |  | 
|  | 4552 | void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) { | 
| Vladimir Marko | b546163 | 2018-10-15 14:24:21 +0100 | [diff] [blame] | 4553 | // Note: if heap poisoning is enabled, the entry point takes care of poisoning the reference. | 
|  | 4554 | QuickEntrypointEnum entrypoint = CodeGenerator::GetArrayAllocationEntrypoint(instruction); | 
| Nicolas Geoffray | d095844 | 2017-01-30 14:57:16 +0000 | [diff] [blame] | 4555 | codegen_->InvokeRuntime(entrypoint, instruction, instruction->GetDexPc()); | 
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4556 | CheckEntrypointTypes<kQuickAllocArrayResolved, void*, mirror::Class*, int32_t>(); | 
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4557 | DCHECK(!codegen_->IsLeafMethod()); | 
|  | 4558 | } | 
|  | 4559 |  | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4560 | void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4561 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4562 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4563 | Location location = parameter_visitor_.GetNextLocation(instruction->GetType()); | 
|  | 4564 | if (location.IsStackSlot()) { | 
|  | 4565 | location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
|  | 4566 | } else if (location.IsDoubleStackSlot()) { | 
|  | 4567 | location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize()); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4568 | } | 
| Nicolas Geoffray | a747a39 | 2014-04-17 14:56:23 +0100 | [diff] [blame] | 4569 | locations->SetOut(location); | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4570 | } | 
|  | 4571 |  | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4572 | void InstructionCodeGeneratorX86::VisitParameterValue( | 
|  | 4573 | HParameterValue* instruction ATTRIBUTE_UNUSED) { | 
|  | 4574 | } | 
|  | 4575 |  | 
|  | 4576 | void LocationsBuilderX86::VisitCurrentMethod(HCurrentMethod* instruction) { | 
|  | 4577 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4578 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); | 
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4579 | locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument)); | 
|  | 4580 | } | 
|  | 4581 |  | 
|  | 4582 | void InstructionCodeGeneratorX86::VisitCurrentMethod(HCurrentMethod* instruction ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4583 | } | 
|  | 4584 |  | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4585 | void LocationsBuilderX86::VisitClassTableGet(HClassTableGet* instruction) { | 
|  | 4586 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4587 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4588 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4589 | locations->SetOut(Location::RequiresRegister()); | 
|  | 4590 | } | 
|  | 4591 |  | 
|  | 4592 | void InstructionCodeGeneratorX86::VisitClassTableGet(HClassTableGet* instruction) { | 
|  | 4593 | LocationSummary* locations = instruction->GetLocations(); | 
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4594 | if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) { | 
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4595 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4596 | instruction->GetIndex(), kX86PointerSize).SizeValue(); | 
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4597 | __ movl(locations->Out().AsRegister<Register>(), | 
|  | 4598 | Address(locations->InAt(0).AsRegister<Register>(), method_offset)); | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4599 | } else { | 
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4600 | uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement( | 
| Matthew Gharrity | 465ecc8 | 2016-07-19 21:32:52 +0000 | [diff] [blame] | 4601 | instruction->GetIndex(), kX86PointerSize)); | 
| Nicolas Geoffray | ff484b9 | 2016-07-13 14:13:48 +0100 | [diff] [blame] | 4602 | __ movl(locations->Out().AsRegister<Register>(), | 
|  | 4603 | Address(locations->InAt(0).AsRegister<Register>(), | 
|  | 4604 | mirror::Class::ImtPtrOffset(kX86PointerSize).Uint32Value())); | 
|  | 4605 | // temp = temp->GetImtEntryAt(method_offset); | 
|  | 4606 | __ movl(locations->Out().AsRegister<Register>(), | 
|  | 4607 | Address(locations->Out().AsRegister<Register>(), method_offset)); | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4608 | } | 
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 4609 | } | 
|  | 4610 |  | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4611 | void LocationsBuilderX86::VisitNot(HNot* not_) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4612 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4613 | new (GetGraph()->GetAllocator()) LocationSummary(not_, LocationSummary::kNoCall); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4614 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4615 | locations->SetOut(Location::SameAsFirstInput()); | 
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4616 | } | 
|  | 4617 |  | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4618 | void InstructionCodeGeneratorX86::VisitNot(HNot* not_) { | 
|  | 4619 | LocationSummary* locations = not_->GetLocations(); | 
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4620 | Location in = locations->InAt(0); | 
| Nicolas Geoffray | a7aca37 | 2014-04-28 17:47:12 +0100 | [diff] [blame] | 4621 | Location out = locations->Out(); | 
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4622 | DCHECK(in.Equals(out)); | 
| Nicolas Geoffray | d8ef2e9 | 2015-02-24 16:02:06 +0000 | [diff] [blame] | 4623 | switch (not_->GetResultType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4624 | case DataType::Type::kInt32: | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4625 | __ notl(out.AsRegister<Register>()); | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4626 | break; | 
|  | 4627 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4628 | case DataType::Type::kInt64: | 
| Roland Levillain | 7056643 | 2014-10-24 16:20:17 +0100 | [diff] [blame] | 4629 | __ notl(out.AsRegisterPairLow<Register>()); | 
|  | 4630 | __ notl(out.AsRegisterPairHigh<Register>()); | 
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4631 | break; | 
|  | 4632 |  | 
|  | 4633 | default: | 
|  | 4634 | LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType(); | 
|  | 4635 | } | 
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4636 | } | 
|  | 4637 |  | 
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4638 | void LocationsBuilderX86::VisitBooleanNot(HBooleanNot* bool_not) { | 
|  | 4639 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4640 | new (GetGraph()->GetAllocator()) LocationSummary(bool_not, LocationSummary::kNoCall); | 
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4641 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 4642 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 4643 | } | 
|  | 4644 |  | 
|  | 4645 | void InstructionCodeGeneratorX86::VisitBooleanNot(HBooleanNot* bool_not) { | 
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4646 | LocationSummary* locations = bool_not->GetLocations(); | 
|  | 4647 | Location in = locations->InAt(0); | 
|  | 4648 | Location out = locations->Out(); | 
|  | 4649 | DCHECK(in.Equals(out)); | 
|  | 4650 | __ xorl(out.AsRegister<Register>(), Immediate(1)); | 
|  | 4651 | } | 
|  | 4652 |  | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4653 | void LocationsBuilderX86::VisitCompare(HCompare* compare) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4654 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4655 | new (GetGraph()->GetAllocator()) LocationSummary(compare, LocationSummary::kNoCall); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4656 | switch (compare->InputAt(0)->GetType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4657 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4658 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4659 | case DataType::Type::kInt8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4660 | case DataType::Type::kUint16: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4661 | case DataType::Type::kInt16: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4662 | case DataType::Type::kInt32: | 
|  | 4663 | case DataType::Type::kInt64: { | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4664 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4665 | locations->SetInAt(1, Location::Any()); | 
|  | 4666 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 4667 | break; | 
|  | 4668 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4669 | case DataType::Type::kFloat32: | 
|  | 4670 | case DataType::Type::kFloat64: { | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4671 | locations->SetInAt(0, Location::RequiresFpuRegister()); | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4672 | if (compare->InputAt(1)->IsX86LoadFromConstantTable()) { | 
|  | 4673 | DCHECK(compare->InputAt(1)->IsEmittedAtUseSite()); | 
|  | 4674 | } else if (compare->InputAt(1)->IsConstant()) { | 
|  | 4675 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 4676 | } else { | 
|  | 4677 | locations->SetInAt(1, Location::Any()); | 
|  | 4678 | } | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4679 | locations->SetOut(Location::RequiresRegister()); | 
|  | 4680 | break; | 
|  | 4681 | } | 
|  | 4682 | default: | 
|  | 4683 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); | 
|  | 4684 | } | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4685 | } | 
|  | 4686 |  | 
|  | 4687 | void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) { | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4688 | LocationSummary* locations = compare->GetLocations(); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 4689 | Register out = locations->Out().AsRegister<Register>(); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4690 | Location left = locations->InAt(0); | 
|  | 4691 | Location right = locations->InAt(1); | 
|  | 4692 |  | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 4693 | NearLabel less, greater, done; | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4694 | Condition less_cond = kLess; | 
|  | 4695 |  | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4696 | switch (compare->InputAt(0)->GetType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4697 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4698 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4699 | case DataType::Type::kInt8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4700 | case DataType::Type::kUint16: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 4701 | case DataType::Type::kInt16: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4702 | case DataType::Type::kInt32: { | 
| Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 4703 | codegen_->GenerateIntCompare(left, right); | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4704 | break; | 
|  | 4705 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4706 | case DataType::Type::kInt64: { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4707 | Register left_low = left.AsRegisterPairLow<Register>(); | 
|  | 4708 | Register left_high = left.AsRegisterPairHigh<Register>(); | 
|  | 4709 | int32_t val_low = 0; | 
|  | 4710 | int32_t val_high = 0; | 
|  | 4711 | bool right_is_const = false; | 
|  | 4712 |  | 
|  | 4713 | if (right.IsConstant()) { | 
|  | 4714 | DCHECK(right.GetConstant()->IsLongConstant()); | 
|  | 4715 | right_is_const = true; | 
|  | 4716 | int64_t val = right.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 4717 | val_low = Low32Bits(val); | 
|  | 4718 | val_high = High32Bits(val); | 
|  | 4719 | } | 
|  | 4720 |  | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4721 | if (right.IsRegisterPair()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4722 | __ cmpl(left_high, right.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4723 | } else if (right.IsDoubleStackSlot()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4724 | __ cmpl(left_high, Address(ESP, right.GetHighStackIndex(kX86WordSize))); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4725 | } else { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4726 | DCHECK(right_is_const) << right; | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4727 | codegen_->Compare32BitValue(left_high, val_high); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4728 | } | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4729 | __ j(kLess, &less);  // Signed compare. | 
|  | 4730 | __ j(kGreater, &greater);  // Signed compare. | 
| Nicolas Geoffray | 56b9ee6 | 2014-10-09 11:47:51 +0100 | [diff] [blame] | 4731 | if (right.IsRegisterPair()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4732 | __ cmpl(left_low, right.AsRegisterPairLow<Register>()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4733 | } else if (right.IsDoubleStackSlot()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4734 | __ cmpl(left_low, Address(ESP, right.GetStackIndex())); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 4735 | } else { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 4736 | DCHECK(right_is_const) << right; | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4737 | codegen_->Compare32BitValue(left_low, val_low); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4738 | } | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4739 | less_cond = kBelow;  // for CF (unsigned). | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4740 | break; | 
|  | 4741 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4742 | case DataType::Type::kFloat32: { | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4743 | GenerateFPCompare(left, right, compare, false); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4744 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4745 | less_cond = kBelow;  // for CF (floats). | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4746 | break; | 
|  | 4747 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4748 | case DataType::Type::kFloat64: { | 
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 4749 | GenerateFPCompare(left, right, compare, true); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4750 | __ j(kUnordered, compare->IsGtBias() ? &greater : &less); | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4751 | less_cond = kBelow;  // for CF (floats). | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4752 | break; | 
|  | 4753 | } | 
|  | 4754 | default: | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4755 | LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType(); | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4756 | } | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4757 |  | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4758 | __ movl(out, Immediate(0)); | 
|  | 4759 | __ j(kEqual, &done); | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 4760 | __ j(less_cond, &less); | 
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4761 |  | 
|  | 4762 | __ Bind(&greater); | 
|  | 4763 | __ movl(out, Immediate(1)); | 
|  | 4764 | __ jmp(&done); | 
|  | 4765 |  | 
|  | 4766 | __ Bind(&less); | 
|  | 4767 | __ movl(out, Immediate(-1)); | 
|  | 4768 |  | 
|  | 4769 | __ Bind(&done); | 
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4770 | } | 
|  | 4771 |  | 
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4772 | void LocationsBuilderX86::VisitPhi(HPhi* instruction) { | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4773 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 4774 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); | 
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4775 | for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) { | 
| Nicolas Geoffray | 31d76b4 | 2014-06-09 15:02:22 +0100 | [diff] [blame] | 4776 | locations->SetInAt(i, Location::Any()); | 
|  | 4777 | } | 
|  | 4778 | locations->SetOut(Location::Any()); | 
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4779 | } | 
|  | 4780 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4781 | void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 4782 | LOG(FATAL) << "Unreachable"; | 
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4783 | } | 
|  | 4784 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 4785 | void CodeGeneratorX86::GenerateMemoryBarrier(MemBarrierKind kind) { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4786 | /* | 
|  | 4787 | * According to the JSR-133 Cookbook, for x86 only StoreLoad/AnyAny barriers need memory fence. | 
|  | 4788 | * All other barriers (LoadAny, AnyStore, StoreStore) are nops due to the x86 memory model. | 
|  | 4789 | * For those cases, all we need to ensure is that there is a scheduling barrier in place. | 
|  | 4790 | */ | 
|  | 4791 | switch (kind) { | 
|  | 4792 | case MemBarrierKind::kAnyAny: { | 
| Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 4793 | MemoryFence(); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4794 | break; | 
|  | 4795 | } | 
|  | 4796 | case MemBarrierKind::kAnyStore: | 
|  | 4797 | case MemBarrierKind::kLoadAny: | 
|  | 4798 | case MemBarrierKind::kStoreStore: { | 
|  | 4799 | // nop | 
|  | 4800 | break; | 
|  | 4801 | } | 
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4802 | case MemBarrierKind::kNTStoreStore: | 
|  | 4803 | // Non-Temporal Store/Store needs an explicit fence. | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4804 | MemoryFence(/* non-temporal= */ true); | 
| Mark Mendell | 7aa04a1 | 2016-01-27 22:39:07 -0500 | [diff] [blame] | 4805 | break; | 
| Nicolas Geoffray | 1a43dd7 | 2014-07-17 15:15:34 +0100 | [diff] [blame] | 4806 | } | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4807 | } | 
|  | 4808 |  | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4809 | HInvokeStaticOrDirect::DispatchInfo CodeGeneratorX86::GetSupportedInvokeStaticOrDirectDispatch( | 
|  | 4810 | const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info, | 
| Nicolas Geoffray | bdb2ecc | 2018-09-18 14:33:55 +0100 | [diff] [blame] | 4811 | ArtMethod* method ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4812 | return desired_dispatch_info; | 
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4813 | } | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4814 |  | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4815 | Register CodeGeneratorX86::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke, | 
|  | 4816 | Register temp) { | 
|  | 4817 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4818 | Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4819 | if (!invoke->GetLocations()->Intrinsified()) { | 
|  | 4820 | return location.AsRegister<Register>(); | 
|  | 4821 | } | 
|  | 4822 | // For intrinsics we allow any location, so it may be on the stack. | 
|  | 4823 | if (!location.IsRegister()) { | 
|  | 4824 | __ movl(temp, Address(ESP, location.GetStackIndex())); | 
|  | 4825 | return temp; | 
|  | 4826 | } | 
|  | 4827 | // For register locations, check if the register was saved. If so, get it from the stack. | 
|  | 4828 | // Note: There is a chance that the register was saved but not overwritten, so we could | 
|  | 4829 | // save one load. However, since this is just an intrinsic slow path we prefer this | 
|  | 4830 | // simple and more robust approach rather that trying to determine if that's the case. | 
|  | 4831 | SlowPathCode* slow_path = GetCurrentSlowPath(); | 
| Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 4832 | DCHECK(slow_path != nullptr);  // For intrinsified invokes the call is emitted on the slow path. | 
|  | 4833 | if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) { | 
|  | 4834 | int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>()); | 
|  | 4835 | __ movl(temp, Address(ESP, stack_offset)); | 
|  | 4836 | return temp; | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4837 | } | 
|  | 4838 | return location.AsRegister<Register>(); | 
|  | 4839 | } | 
|  | 4840 |  | 
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4841 | void CodeGeneratorX86::GenerateStaticOrDirectCall( | 
|  | 4842 | HInvokeStaticOrDirect* invoke, Location temp, SlowPathCode* slow_path) { | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4843 | Location callee_method = temp;  // For all kinds except kRecursive, callee will be in temp. | 
|  | 4844 | switch (invoke->GetMethodLoadKind()) { | 
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4845 | case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: { | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4846 | // temp = thread->string_init_entrypoint | 
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4847 | uint32_t offset = | 
|  | 4848 | GetThreadOffset<kX86PointerSize>(invoke->GetStringInitEntryPoint()).Int32Value(); | 
|  | 4849 | __ fs()->movl(temp.AsRegister<Register>(), Address::Absolute(offset)); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4850 | break; | 
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4851 | } | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4852 | case HInvokeStaticOrDirect::MethodLoadKind::kRecursive: | 
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4853 | callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4854 | break; | 
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4855 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageLinkTimePcRelative: { | 
|  | 4856 | DCHECK(GetCompilerOptions().IsBootImage()); | 
|  | 4857 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, | 
|  | 4858 | temp.AsRegister<Register>()); | 
|  | 4859 | __ leal(temp.AsRegister<Register>(), Address(base_reg, CodeGeneratorX86::kDummy32BitOffset)); | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4860 | RecordBootImageMethodPatch(invoke); | 
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4861 | break; | 
|  | 4862 | } | 
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4863 | case HInvokeStaticOrDirect::MethodLoadKind::kBootImageRelRo: { | 
|  | 4864 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, | 
|  | 4865 | temp.AsRegister<Register>()); | 
|  | 4866 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); | 
|  | 4867 | RecordBootImageRelRoPatch( | 
|  | 4868 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(), | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 4869 | GetBootImageOffset(invoke)); | 
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4870 | break; | 
|  | 4871 | } | 
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4872 | case HInvokeStaticOrDirect::MethodLoadKind::kBssEntry: { | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4873 | Register base_reg = GetInvokeStaticOrDirectExtraParameter(invoke, | 
|  | 4874 | temp.AsRegister<Register>()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4875 | __ movl(temp.AsRegister<Register>(), Address(base_reg, kDummy32BitOffset)); | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4876 | RecordMethodBssEntryPatch(invoke); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4877 | break; | 
|  | 4878 | } | 
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4879 | case HInvokeStaticOrDirect::MethodLoadKind::kJitDirectAddress: | 
|  | 4880 | __ movl(temp.AsRegister<Register>(), Immediate(invoke->GetMethodAddress())); | 
|  | 4881 | break; | 
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4882 | case HInvokeStaticOrDirect::MethodLoadKind::kRuntimeCall: { | 
|  | 4883 | GenerateInvokeStaticOrDirectRuntimeCall(invoke, temp, slow_path); | 
|  | 4884 | return;  // No code pointer retrieval; the runtime performs the call directly. | 
| Vladimir Marko | 9b688a0 | 2015-05-06 14:12:42 +0100 | [diff] [blame] | 4885 | } | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4886 | } | 
|  | 4887 |  | 
|  | 4888 | switch (invoke->GetCodePtrLocation()) { | 
|  | 4889 | case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf: | 
|  | 4890 | __ call(GetFrameEntryLabel()); | 
|  | 4891 | break; | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4892 | case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod: | 
|  | 4893 | // (callee_method + offset_of_quick_compiled_code)() | 
|  | 4894 | __ call(Address(callee_method.AsRegister<Register>(), | 
|  | 4895 | ArtMethod::EntryPointFromQuickCompiledCodeOffset( | 
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4896 | kX86PointerSize).Int32Value())); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4897 | break; | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4898 | } | 
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4899 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4900 |  | 
|  | 4901 | DCHECK(!IsLeafMethod()); | 
| Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 4902 | } | 
|  | 4903 |  | 
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4904 | void CodeGeneratorX86::GenerateVirtualCall( | 
|  | 4905 | HInvokeVirtual* invoke, Location temp_in, SlowPathCode* slow_path) { | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4906 | Register temp = temp_in.AsRegister<Register>(); | 
|  | 4907 | uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset( | 
|  | 4908 | invoke->GetVTableIndex(), kX86PointerSize).Uint32Value(); | 
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4909 |  | 
|  | 4910 | // Use the calling convention instead of the location of the receiver, as | 
|  | 4911 | // intrinsics may have put the receiver in a different register. In the intrinsics | 
|  | 4912 | // slow path, the arguments have been moved to the right place, so here we are | 
|  | 4913 | // guaranteed that the receiver is the first register of the calling convention. | 
|  | 4914 | InvokeDexCallingConvention calling_convention; | 
|  | 4915 | Register receiver = calling_convention.GetRegisterAt(0); | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4916 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4917 | // /* HeapReference<Class> */ temp = receiver->klass_ | 
| Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4918 | __ movl(temp, Address(receiver, class_offset)); | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4919 | MaybeRecordImplicitNullCheck(invoke); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 4920 | // Instead of simply (possibly) unpoisoning `temp` here, we should | 
|  | 4921 | // emit a read barrier for the previous class reference load. | 
|  | 4922 | // However this is not required in practice, as this is an | 
|  | 4923 | // intermediate/temporary reference and because the current | 
|  | 4924 | // concurrent copying collector keeps the from-space memory | 
|  | 4925 | // intact/accessible until the end of the marking phase (the | 
|  | 4926 | // concurrent copying collector may not in the future). | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4927 | __ MaybeUnpoisonHeapReference(temp); | 
|  | 4928 | // temp = temp->GetMethodAt(method_offset); | 
|  | 4929 | __ movl(temp, Address(temp, method_offset)); | 
|  | 4930 | // call temp->GetEntryPoint(); | 
|  | 4931 | __ call(Address( | 
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 4932 | temp, ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86PointerSize).Int32Value())); | 
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4933 | RecordPcInfo(invoke, invoke->GetDexPc(), slow_path); | 
| Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 4934 | } | 
|  | 4935 |  | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4936 | void CodeGeneratorX86::RecordBootImageIntrinsicPatch(HX86ComputeBaseMethodAddress* method_address, | 
|  | 4937 | uint32_t intrinsic_data) { | 
|  | 4938 | boot_image_intrinsic_patches_.emplace_back( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4939 | method_address, /* target_dex_file= */ nullptr, intrinsic_data); | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 4940 | __ Bind(&boot_image_intrinsic_patches_.back().label); | 
|  | 4941 | } | 
|  | 4942 |  | 
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4943 | void CodeGeneratorX86::RecordBootImageRelRoPatch(HX86ComputeBaseMethodAddress* method_address, | 
|  | 4944 | uint32_t boot_image_offset) { | 
|  | 4945 | boot_image_method_patches_.emplace_back( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 4946 | method_address, /* target_dex_file= */ nullptr, boot_image_offset); | 
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4947 | __ Bind(&boot_image_method_patches_.back().label); | 
|  | 4948 | } | 
|  | 4949 |  | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4950 | void CodeGeneratorX86::RecordBootImageMethodPatch(HInvokeStaticOrDirect* invoke) { | 
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4951 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4952 | HX86ComputeBaseMethodAddress* method_address = | 
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4953 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4954 | boot_image_method_patches_.emplace_back( | 
|  | 4955 | method_address, invoke->GetTargetMethod().dex_file, invoke->GetTargetMethod().index); | 
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4956 | __ Bind(&boot_image_method_patches_.back().label); | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 4957 | } | 
|  | 4958 |  | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4959 | void CodeGeneratorX86::RecordMethodBssEntryPatch(HInvokeStaticOrDirect* invoke) { | 
|  | 4960 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); | 
|  | 4961 | HX86ComputeBaseMethodAddress* method_address = | 
|  | 4962 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); | 
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4963 | // Add the patch entry and bind its label at the end of the instruction. | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4964 | method_bss_entry_patches_.emplace_back( | 
|  | 4965 | method_address, &GetGraph()->GetDexFile(), invoke->GetDexMethodIndex()); | 
|  | 4966 | __ Bind(&method_bss_entry_patches_.back().label); | 
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4967 | } | 
|  | 4968 |  | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4969 | void CodeGeneratorX86::RecordBootImageTypePatch(HLoadClass* load_class) { | 
|  | 4970 | HX86ComputeBaseMethodAddress* method_address = | 
|  | 4971 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); | 
|  | 4972 | boot_image_type_patches_.emplace_back( | 
|  | 4973 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); | 
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4974 | __ Bind(&boot_image_type_patches_.back().label); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 4975 | } | 
|  | 4976 |  | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4977 | Label* CodeGeneratorX86::NewTypeBssEntryPatch(HLoadClass* load_class) { | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4978 | HX86ComputeBaseMethodAddress* method_address = | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4979 | load_class->InputAt(0)->AsX86ComputeBaseMethodAddress(); | 
|  | 4980 | type_bss_entry_patches_.emplace_back( | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4981 | method_address, &load_class->GetDexFile(), load_class->GetTypeIndex().index_); | 
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 4982 | return &type_bss_entry_patches_.back().label; | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 4983 | } | 
|  | 4984 |  | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4985 | void CodeGeneratorX86::RecordBootImageStringPatch(HLoadString* load_string) { | 
|  | 4986 | HX86ComputeBaseMethodAddress* method_address = | 
|  | 4987 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); | 
|  | 4988 | boot_image_string_patches_.emplace_back( | 
|  | 4989 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); | 
|  | 4990 | __ Bind(&boot_image_string_patches_.back().label); | 
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4991 | } | 
|  | 4992 |  | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4993 | Label* CodeGeneratorX86::NewStringBssEntryPatch(HLoadString* load_string) { | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4994 | HX86ComputeBaseMethodAddress* method_address = | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 4995 | load_string->InputAt(0)->AsX86ComputeBaseMethodAddress(); | 
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4996 | string_bss_entry_patches_.emplace_back( | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 4997 | method_address, &load_string->GetDexFile(), load_string->GetStringIndex().index_); | 
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 4998 | return &string_bss_entry_patches_.back().label; | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 4999 | } | 
|  | 5000 |  | 
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5001 | void CodeGeneratorX86::LoadBootImageAddress(Register reg, | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5002 | uint32_t boot_image_reference, | 
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5003 | HInvokeStaticOrDirect* invoke) { | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5004 | if (GetCompilerOptions().IsBootImage()) { | 
|  | 5005 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); | 
|  | 5006 | HX86ComputeBaseMethodAddress* method_address = | 
|  | 5007 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); | 
|  | 5008 | DCHECK(method_address != nullptr); | 
|  | 5009 | Register method_address_reg = | 
|  | 5010 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); | 
|  | 5011 | __ leal(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); | 
|  | 5012 | RecordBootImageIntrinsicPatch(method_address, boot_image_reference); | 
| Vladimir Marko | a2da9b9 | 2018-10-10 14:21:55 +0100 | [diff] [blame] | 5013 | } else if (GetCompilerOptions().GetCompilePic()) { | 
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5014 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); | 
|  | 5015 | HX86ComputeBaseMethodAddress* method_address = | 
|  | 5016 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); | 
|  | 5017 | DCHECK(method_address != nullptr); | 
|  | 5018 | Register method_address_reg = | 
|  | 5019 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); | 
|  | 5020 | __ movl(reg, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5021 | RecordBootImageRelRoPatch(method_address, boot_image_reference); | 
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5022 | } else { | 
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 5023 | DCHECK(Runtime::Current()->UseJitCompilation()); | 
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5024 | gc::Heap* heap = Runtime::Current()->GetHeap(); | 
|  | 5025 | DCHECK(!heap->GetBootImageSpaces().empty()); | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5026 | const uint8_t* address = heap->GetBootImageSpaces()[0]->Begin() + boot_image_reference; | 
| Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 5027 | __ movl(reg, Immediate(dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(address)))); | 
|  | 5028 | } | 
|  | 5029 | } | 
|  | 5030 |  | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5031 | void CodeGeneratorX86::AllocateInstanceForIntrinsic(HInvokeStaticOrDirect* invoke, | 
|  | 5032 | uint32_t boot_image_offset) { | 
|  | 5033 | DCHECK(invoke->IsStatic()); | 
|  | 5034 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 5035 | Register argument = calling_convention.GetRegisterAt(0); | 
|  | 5036 | if (GetCompilerOptions().IsBootImage()) { | 
|  | 5037 | DCHECK_EQ(boot_image_offset, IntrinsicVisitor::IntegerValueOfInfo::kInvalidReference); | 
|  | 5038 | // Load the class the same way as for HLoadClass::LoadKind::kBootImageLinkTimePcRelative. | 
|  | 5039 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); | 
|  | 5040 | HX86ComputeBaseMethodAddress* method_address = | 
|  | 5041 | invoke->InputAt(invoke->GetSpecialInputIndex())->AsX86ComputeBaseMethodAddress(); | 
|  | 5042 | DCHECK(method_address != nullptr); | 
|  | 5043 | Register method_address_reg = | 
|  | 5044 | invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex()).AsRegister<Register>(); | 
|  | 5045 | __ leal(argument, Address(method_address_reg, CodeGeneratorX86::kDummy32BitOffset)); | 
|  | 5046 | MethodReference target_method = invoke->GetTargetMethod(); | 
|  | 5047 | dex::TypeIndex type_idx = target_method.dex_file->GetMethodId(target_method.index).class_idx_; | 
|  | 5048 | boot_image_type_patches_.emplace_back(method_address, target_method.dex_file, type_idx.index_); | 
|  | 5049 | __ Bind(&boot_image_type_patches_.back().label); | 
|  | 5050 | } else { | 
|  | 5051 | LoadBootImageAddress(argument, boot_image_offset, invoke); | 
|  | 5052 | } | 
|  | 5053 | InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); | 
|  | 5054 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); | 
|  | 5055 | } | 
|  | 5056 |  | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5057 | // The label points to the end of the "movl" or another instruction but the literal offset | 
|  | 5058 | // for method patch needs to point to the embedded constant which occupies the last 4 bytes. | 
|  | 5059 | constexpr uint32_t kLabelPositionToLiteralOffsetAdjustment = 4u; | 
|  | 5060 |  | 
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5061 | template <linker::LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)> | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5062 | inline void CodeGeneratorX86::EmitPcRelativeLinkerPatches( | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5063 | const ArenaDeque<X86PcRelativePatchInfo>& infos, | 
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5064 | ArenaVector<linker::LinkerPatch>* linker_patches) { | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 5065 | for (const X86PcRelativePatchInfo& info : infos) { | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5066 | uint32_t literal_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5067 | linker_patches->push_back(Factory(literal_offset, | 
|  | 5068 | info.target_dex_file, | 
|  | 5069 | GetMethodAddressOffset(info.method_address), | 
|  | 5070 | info.offset_or_index)); | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5071 | } | 
|  | 5072 | } | 
|  | 5073 |  | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5074 | template <linker::LinkerPatch (*Factory)(size_t, uint32_t, uint32_t)> | 
|  | 5075 | linker::LinkerPatch NoDexFileAdapter(size_t literal_offset, | 
|  | 5076 | const DexFile* target_dex_file, | 
|  | 5077 | uint32_t pc_insn_offset, | 
|  | 5078 | uint32_t boot_image_offset) { | 
|  | 5079 | DCHECK(target_dex_file == nullptr);  // Unused for these patches, should be null. | 
|  | 5080 | return Factory(literal_offset, pc_insn_offset, boot_image_offset); | 
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5081 | } | 
|  | 5082 |  | 
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5083 | void CodeGeneratorX86::EmitLinkerPatches(ArenaVector<linker::LinkerPatch>* linker_patches) { | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5084 | DCHECK(linker_patches->empty()); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5085 | size_t size = | 
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5086 | boot_image_method_patches_.size() + | 
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 5087 | method_bss_entry_patches_.size() + | 
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5088 | boot_image_type_patches_.size() + | 
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 5089 | type_bss_entry_patches_.size() + | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5090 | boot_image_string_patches_.size() + | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5091 | string_bss_entry_patches_.size() + | 
|  | 5092 | boot_image_intrinsic_patches_.size(); | 
| Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 5093 | linker_patches->reserve(size); | 
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 5094 | if (GetCompilerOptions().IsBootImage()) { | 
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5095 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeMethodPatch>( | 
|  | 5096 | boot_image_method_patches_, linker_patches); | 
|  | 5097 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeTypePatch>( | 
|  | 5098 | boot_image_type_patches_, linker_patches); | 
|  | 5099 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::RelativeStringPatch>( | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 5100 | boot_image_string_patches_, linker_patches); | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5101 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::IntrinsicReferencePatch>>( | 
|  | 5102 | boot_image_intrinsic_patches_, linker_patches); | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 5103 | } else { | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5104 | EmitPcRelativeLinkerPatches<NoDexFileAdapter<linker::LinkerPatch::DataBimgRelRoPatch>>( | 
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 5105 | boot_image_method_patches_, linker_patches); | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 5106 | DCHECK(boot_image_type_patches_.empty()); | 
|  | 5107 | DCHECK(boot_image_string_patches_.empty()); | 
| Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 5108 | DCHECK(boot_image_intrinsic_patches_.empty()); | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5109 | } | 
| Vladimir Marko | d8dbc8d | 2017-09-20 13:37:47 +0100 | [diff] [blame] | 5110 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::MethodBssEntryPatch>( | 
|  | 5111 | method_bss_entry_patches_, linker_patches); | 
|  | 5112 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::TypeBssEntryPatch>( | 
|  | 5113 | type_bss_entry_patches_, linker_patches); | 
|  | 5114 | EmitPcRelativeLinkerPatches<linker::LinkerPatch::StringBssEntryPatch>( | 
|  | 5115 | string_bss_entry_patches_, linker_patches); | 
| Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 5116 | DCHECK_EQ(size, linker_patches->size()); | 
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5117 | } | 
|  | 5118 |  | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5119 | void CodeGeneratorX86::MarkGCCard(Register temp, | 
|  | 5120 | Register card, | 
|  | 5121 | Register object, | 
|  | 5122 | Register value, | 
|  | 5123 | bool value_can_be_null) { | 
| Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 5124 | NearLabel is_null; | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5125 | if (value_can_be_null) { | 
|  | 5126 | __ testl(value, value); | 
|  | 5127 | __ j(kEqual, &is_null); | 
|  | 5128 | } | 
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5129 | // Load the address of the card table into `card`. | 
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 5130 | __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86PointerSize>().Int32Value())); | 
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5131 | // Calculate the offset (in the card table) of the card corresponding to | 
|  | 5132 | // `object`. | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5133 | __ movl(temp, object); | 
|  | 5134 | __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift)); | 
| Roland Levillain | c73f052 | 2018-08-14 15:16:50 +0100 | [diff] [blame] | 5135 | // Write the `art::gc::accounting::CardTable::kCardDirty` value into the | 
|  | 5136 | // `object`'s card. | 
|  | 5137 | // | 
|  | 5138 | // Register `card` contains the address of the card table. Note that the card | 
|  | 5139 | // table's base is biased during its creation so that it always starts at an | 
|  | 5140 | // address whose least-significant byte is equal to `kCardDirty` (see | 
|  | 5141 | // art::gc::accounting::CardTable::Create). Therefore the MOVB instruction | 
|  | 5142 | // below writes the `kCardDirty` (byte) value into the `object`'s card | 
|  | 5143 | // (located at `card + object >> kCardShift`). | 
|  | 5144 | // | 
|  | 5145 | // This dual use of the value in register `card` (1. to calculate the location | 
|  | 5146 | // of the card to mark; and 2. to load the `kCardDirty` value) saves a load | 
|  | 5147 | // (no need to explicitly load `kCardDirty` as an immediate value). | 
| Nicolas Geoffray | 5b4b898 | 2014-12-18 17:45:56 +0000 | [diff] [blame] | 5148 | __ movb(Address(temp, card, TIMES_1, 0), | 
|  | 5149 | X86ManagedRegister::FromCpuRegister(card).AsByteRegister()); | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5150 | if (value_can_be_null) { | 
|  | 5151 | __ Bind(&is_null); | 
|  | 5152 | } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5153 | } | 
|  | 5154 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5155 | void LocationsBuilderX86::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) { | 
|  | 5156 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5157 |  | 
|  | 5158 | bool object_field_get_with_read_barrier = | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5159 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5160 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5161 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, | 
|  | 5162 | kEmitCompilerReadBarrier | 
|  | 5163 | ? LocationSummary::kCallOnSlowPath | 
|  | 5164 | : LocationSummary::kNoCall); | 
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5165 | if (object_field_get_with_read_barrier && kUseBakerReadBarrier) { | 
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5166 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty());  // No caller-save registers. | 
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5167 | } | 
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5168 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5169 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5170 | if (DataType::IsFloatingPointType(instruction->GetType())) { | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5171 | locations->SetOut(Location::RequiresFpuRegister()); | 
|  | 5172 | } else { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5173 | // The output overlaps in case of long: we don't want the low move | 
|  | 5174 | // to overwrite the object's location.  Likewise, in the case of | 
|  | 5175 | // an object field get with read barriers enabled, we do not want | 
|  | 5176 | // the move to overwrite the object's location, as we need it to emit | 
|  | 5177 | // the read barrier. | 
|  | 5178 | locations->SetOut( | 
|  | 5179 | Location::RequiresRegister(), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5180 | (object_field_get_with_read_barrier || instruction->GetType() == DataType::Type::kInt64) ? | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5181 | Location::kOutputOverlap : | 
|  | 5182 | Location::kNoOutputOverlap); | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5183 | } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5184 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5185 | if (field_info.IsVolatile() && (field_info.GetFieldType() == DataType::Type::kInt64)) { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5186 | // Long values can be loaded atomically into an XMM using movsd. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5187 | // So we use an XMM register as a temp to achieve atomicity (first | 
|  | 5188 | // load the temp into the XMM and then copy the XMM into the | 
|  | 5189 | // output, 32 bits at a time). | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5190 | locations->AddTemp(Location::RequiresFpuRegister()); | 
|  | 5191 | } | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5192 | } | 
|  | 5193 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5194 | void InstructionCodeGeneratorX86::HandleFieldGet(HInstruction* instruction, | 
|  | 5195 | const FieldInfo& field_info) { | 
|  | 5196 | DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet()); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5197 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5198 | LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5199 | Location base_loc = locations->InAt(0); | 
|  | 5200 | Register base = base_loc.AsRegister<Register>(); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5201 | Location out = locations->Out(); | 
|  | 5202 | bool is_volatile = field_info.IsVolatile(); | 
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5203 | DCHECK_EQ(DataType::Size(field_info.GetFieldType()), DataType::Size(instruction->GetType())); | 
|  | 5204 | DataType::Type load_type = instruction->GetType(); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5205 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); | 
|  | 5206 |  | 
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5207 | switch (load_type) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5208 | case DataType::Type::kBool: | 
|  | 5209 | case DataType::Type::kUint8: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5210 | __ movzxb(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5211 | break; | 
|  | 5212 | } | 
|  | 5213 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5214 | case DataType::Type::kInt8: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5215 | __ movsxb(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5216 | break; | 
|  | 5217 | } | 
|  | 5218 |  | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5219 | case DataType::Type::kUint16: { | 
|  | 5220 | __ movzxw(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5221 | break; | 
|  | 5222 | } | 
|  | 5223 |  | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5224 | case DataType::Type::kInt16: { | 
|  | 5225 | __ movsxw(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5226 | break; | 
|  | 5227 | } | 
|  | 5228 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5229 | case DataType::Type::kInt32: | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5230 | __ movl(out.AsRegister<Register>(), Address(base, offset)); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5231 | break; | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5232 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5233 | case DataType::Type::kReference: { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5234 | // /* HeapReference<Object> */ out = *(base + offset) | 
|  | 5235 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5236 | // Note that a potential implicit null check is handled in this | 
|  | 5237 | // CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier call. | 
|  | 5238 | codegen_->GenerateFieldLoadWithBakerReadBarrier( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5239 | instruction, out, base, offset, /* needs_null_check= */ true); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5240 | if (is_volatile) { | 
|  | 5241 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); | 
|  | 5242 | } | 
|  | 5243 | } else { | 
|  | 5244 | __ movl(out.AsRegister<Register>(), Address(base, offset)); | 
|  | 5245 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5246 | if (is_volatile) { | 
|  | 5247 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); | 
|  | 5248 | } | 
|  | 5249 | // If read barriers are enabled, emit read barriers other than | 
|  | 5250 | // Baker's using a slow path (and also unpoison the loaded | 
|  | 5251 | // reference, if heap poisoning is enabled). | 
|  | 5252 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out, out, base_loc, offset); | 
|  | 5253 | } | 
|  | 5254 | break; | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5255 | } | 
|  | 5256 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5257 | case DataType::Type::kInt64: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5258 | if (is_volatile) { | 
|  | 5259 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
|  | 5260 | __ movsd(temp, Address(base, offset)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5261 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5262 | __ movd(out.AsRegisterPairLow<Register>(), temp); | 
|  | 5263 | __ psrlq(temp, Immediate(32)); | 
|  | 5264 | __ movd(out.AsRegisterPairHigh<Register>(), temp); | 
|  | 5265 | } else { | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5266 | DCHECK_NE(base, out.AsRegisterPairLow<Register>()); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5267 | __ movl(out.AsRegisterPairLow<Register>(), Address(base, offset)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5268 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5269 | __ movl(out.AsRegisterPairHigh<Register>(), Address(base, kX86WordSize + offset)); | 
|  | 5270 | } | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5271 | break; | 
|  | 5272 | } | 
|  | 5273 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5274 | case DataType::Type::kFloat32: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5275 | __ movss(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); | 
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5276 | break; | 
|  | 5277 | } | 
|  | 5278 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5279 | case DataType::Type::kFloat64: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5280 | __ movsd(out.AsFpuRegister<XmmRegister>(), Address(base, offset)); | 
| Nicolas Geoffray | 52e832b | 2014-11-06 15:15:31 +0000 | [diff] [blame] | 5281 | break; | 
|  | 5282 | } | 
|  | 5283 |  | 
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5284 | case DataType::Type::kUint32: | 
|  | 5285 | case DataType::Type::kUint64: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5286 | case DataType::Type::kVoid: | 
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5287 | LOG(FATAL) << "Unreachable type " << load_type; | 
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5288 | UNREACHABLE(); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5289 | } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5290 |  | 
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5291 | if (load_type == DataType::Type::kReference || load_type == DataType::Type::kInt64) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5292 | // Potential implicit null checks, in the case of reference or | 
|  | 5293 | // long fields, are handled in the previous switch statement. | 
|  | 5294 | } else { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5295 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5296 | } | 
|  | 5297 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5298 | if (is_volatile) { | 
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5299 | if (load_type == DataType::Type::kReference) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5300 | // Memory barriers, in the case of references, are also handled | 
|  | 5301 | // in the previous switch statement. | 
|  | 5302 | } else { | 
|  | 5303 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); | 
|  | 5304 | } | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5305 | } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5306 | } | 
|  | 5307 |  | 
|  | 5308 | void LocationsBuilderX86::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) { | 
|  | 5309 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); | 
|  | 5310 |  | 
|  | 5311 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5312 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5313 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 5314 | bool is_volatile = field_info.IsVolatile(); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5315 | DataType::Type field_type = field_info.GetFieldType(); | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5316 | bool is_byte_type = DataType::Size(field_type) == 1u; | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5317 |  | 
|  | 5318 | // The register allocator does not support multiple | 
|  | 5319 | // inputs that die at entry with one in a specific register. | 
|  | 5320 | if (is_byte_type) { | 
|  | 5321 | // Ensure the value is in a byte register. | 
|  | 5322 | locations->SetInAt(1, Location::RegisterLocation(EAX)); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5323 | } else if (DataType::IsFloatingPointType(field_type)) { | 
|  | 5324 | if (is_volatile && field_type == DataType::Type::kFloat64) { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5325 | // In order to satisfy the semantics of volatile, this must be a single instruction store. | 
|  | 5326 | locations->SetInAt(1, Location::RequiresFpuRegister()); | 
|  | 5327 | } else { | 
|  | 5328 | locations->SetInAt(1, Location::FpuRegisterOrConstant(instruction->InputAt(1))); | 
|  | 5329 | } | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5330 | } else if (is_volatile && field_type == DataType::Type::kInt64) { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5331 | // In order to satisfy the semantics of volatile, this must be a single instruction store. | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5332 | locations->SetInAt(1, Location::RequiresRegister()); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5333 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5334 | // 64bits value can be atomically written to an address with movsd and an XMM register. | 
|  | 5335 | // We need two XMM registers because there's no easier way to (bit) copy a register pair | 
|  | 5336 | // into a single XMM register (we copy each pair part into the XMMs and then interleave them). | 
|  | 5337 | // NB: We could make the register allocator understand fp_reg <-> core_reg moves but given the | 
|  | 5338 | // isolated cases when we need this it isn't worth adding the extra complexity. | 
|  | 5339 | locations->AddTemp(Location::RequiresFpuRegister()); | 
|  | 5340 | locations->AddTemp(Location::RequiresFpuRegister()); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5341 | } else { | 
|  | 5342 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 5343 |  | 
|  | 5344 | if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) { | 
|  | 5345 | // Temporary registers for the write barrier. | 
|  | 5346 | locations->AddTemp(Location::RequiresRegister());  // May be used for reference poisoning too. | 
|  | 5347 | // Ensure the card is in a byte register. | 
|  | 5348 | locations->AddTemp(Location::RegisterLocation(ECX)); | 
|  | 5349 | } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5350 | } | 
|  | 5351 | } | 
|  | 5352 |  | 
|  | 5353 | void InstructionCodeGeneratorX86::HandleFieldSet(HInstruction* instruction, | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5354 | const FieldInfo& field_info, | 
|  | 5355 | bool value_can_be_null) { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5356 | DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet()); | 
|  | 5357 |  | 
|  | 5358 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 5359 | Register base = locations->InAt(0).AsRegister<Register>(); | 
|  | 5360 | Location value = locations->InAt(1); | 
|  | 5361 | bool is_volatile = field_info.IsVolatile(); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5362 | DataType::Type field_type = field_info.GetFieldType(); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5363 | uint32_t offset = field_info.GetFieldOffset().Uint32Value(); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5364 | bool needs_write_barrier = | 
|  | 5365 | CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1)); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5366 |  | 
|  | 5367 | if (is_volatile) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5368 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyStore); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5369 | } | 
|  | 5370 |  | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5371 | bool maybe_record_implicit_null_check_done = false; | 
|  | 5372 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5373 | switch (field_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5374 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5375 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5376 | case DataType::Type::kInt8: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5377 | __ movb(Address(base, offset), value.AsRegister<ByteRegister>()); | 
|  | 5378 | break; | 
|  | 5379 | } | 
|  | 5380 |  | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5381 | case DataType::Type::kUint16: | 
|  | 5382 | case DataType::Type::kInt16: { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5383 | if (value.IsConstant()) { | 
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5384 | __ movw(Address(base, offset), | 
|  | 5385 | Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5386 | } else { | 
|  | 5387 | __ movw(Address(base, offset), value.AsRegister<Register>()); | 
|  | 5388 | } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5389 | break; | 
|  | 5390 | } | 
|  | 5391 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5392 | case DataType::Type::kInt32: | 
|  | 5393 | case DataType::Type::kReference: { | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5394 | if (kPoisonHeapReferences && needs_write_barrier) { | 
|  | 5395 | // Note that in the case where `value` is a null reference, | 
|  | 5396 | // we do not enter this block, as the reference does not | 
|  | 5397 | // need poisoning. | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5398 | DCHECK_EQ(field_type, DataType::Type::kReference); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5399 | Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 5400 | __ movl(temp, value.AsRegister<Register>()); | 
|  | 5401 | __ PoisonHeapReference(temp); | 
|  | 5402 | __ movl(Address(base, offset), temp); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5403 | } else if (value.IsConstant()) { | 
|  | 5404 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); | 
|  | 5405 | __ movl(Address(base, offset), Immediate(v)); | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5406 | } else { | 
| Nicolas Geoffray | 0397163 | 2016-03-17 10:44:24 +0000 | [diff] [blame] | 5407 | DCHECK(value.IsRegister()) << value; | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5408 | __ movl(Address(base, offset), value.AsRegister<Register>()); | 
|  | 5409 | } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5410 | break; | 
|  | 5411 | } | 
|  | 5412 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5413 | case DataType::Type::kInt64: { | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5414 | if (is_volatile) { | 
|  | 5415 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); | 
|  | 5416 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); | 
|  | 5417 | __ movd(temp1, value.AsRegisterPairLow<Register>()); | 
|  | 5418 | __ movd(temp2, value.AsRegisterPairHigh<Register>()); | 
|  | 5419 | __ punpckldq(temp1, temp2); | 
|  | 5420 | __ movsd(Address(base, offset), temp1); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5421 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5422 | } else if (value.IsConstant()) { | 
|  | 5423 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); | 
|  | 5424 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); | 
|  | 5425 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5426 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5427 | } else { | 
|  | 5428 | __ movl(Address(base, offset), value.AsRegisterPairLow<Register>()); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5429 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5430 | __ movl(Address(base, kX86WordSize + offset), value.AsRegisterPairHigh<Register>()); | 
|  | 5431 | } | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5432 | maybe_record_implicit_null_check_done = true; | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5433 | break; | 
|  | 5434 | } | 
|  | 5435 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5436 | case DataType::Type::kFloat32: { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5437 | if (value.IsConstant()) { | 
|  | 5438 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); | 
|  | 5439 | __ movl(Address(base, offset), Immediate(v)); | 
|  | 5440 | } else { | 
|  | 5441 | __ movss(Address(base, offset), value.AsFpuRegister<XmmRegister>()); | 
|  | 5442 | } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5443 | break; | 
|  | 5444 | } | 
|  | 5445 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5446 | case DataType::Type::kFloat64: { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5447 | if (value.IsConstant()) { | 
|  | 5448 | int64_t v = CodeGenerator::GetInt64ValueOf(value.GetConstant()); | 
|  | 5449 | __ movl(Address(base, offset), Immediate(Low32Bits(v))); | 
|  | 5450 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5451 | __ movl(Address(base, kX86WordSize + offset), Immediate(High32Bits(v))); | 
|  | 5452 | maybe_record_implicit_null_check_done = true; | 
|  | 5453 | } else { | 
|  | 5454 | __ movsd(Address(base, offset), value.AsFpuRegister<XmmRegister>()); | 
|  | 5455 | } | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5456 | break; | 
|  | 5457 | } | 
|  | 5458 |  | 
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5459 | case DataType::Type::kUint32: | 
|  | 5460 | case DataType::Type::kUint64: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5461 | case DataType::Type::kVoid: | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5462 | LOG(FATAL) << "Unreachable type " << field_type; | 
|  | 5463 | UNREACHABLE(); | 
|  | 5464 | } | 
|  | 5465 |  | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5466 | if (!maybe_record_implicit_null_check_done) { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5467 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5468 | } | 
|  | 5469 |  | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 5470 | if (needs_write_barrier) { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5471 | Register temp = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 5472 | Register card = locations->GetTemp(1).AsRegister<Register>(); | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5473 | codegen_->MarkGCCard(temp, card, base, value.AsRegister<Register>(), value_can_be_null); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5474 | } | 
|  | 5475 |  | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5476 | if (is_volatile) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5477 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kAnyAny); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5478 | } | 
|  | 5479 | } | 
|  | 5480 |  | 
|  | 5481 | void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
|  | 5482 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
|  | 5483 | } | 
|  | 5484 |  | 
|  | 5485 | void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) { | 
|  | 5486 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
|  | 5487 | } | 
|  | 5488 |  | 
|  | 5489 | void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
|  | 5490 | HandleFieldSet(instruction, instruction->GetFieldInfo()); | 
|  | 5491 | } | 
|  | 5492 |  | 
|  | 5493 | void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) { | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5494 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5495 | } | 
|  | 5496 |  | 
|  | 5497 | void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
|  | 5498 | HandleFieldSet(instruction, instruction->GetFieldInfo()); | 
|  | 5499 | } | 
|  | 5500 |  | 
|  | 5501 | void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) { | 
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5502 | HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetValueCanBeNull()); | 
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5503 | } | 
|  | 5504 |  | 
|  | 5505 | void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
|  | 5506 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
|  | 5507 | } | 
|  | 5508 |  | 
|  | 5509 | void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) { | 
|  | 5510 | HandleFieldGet(instruction, instruction->GetFieldInfo()); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5511 | } | 
|  | 5512 |  | 
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5513 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldGet( | 
|  | 5514 | HUnresolvedInstanceFieldGet* instruction) { | 
|  | 5515 | FieldAccessCallingConventionX86 calling_convention; | 
|  | 5516 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 5517 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 5518 | } | 
|  | 5519 |  | 
|  | 5520 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldGet( | 
|  | 5521 | HUnresolvedInstanceFieldGet* instruction) { | 
|  | 5522 | FieldAccessCallingConventionX86 calling_convention; | 
|  | 5523 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 5524 | instruction->GetFieldType(), | 
|  | 5525 | instruction->GetFieldIndex(), | 
|  | 5526 | instruction->GetDexPc(), | 
|  | 5527 | calling_convention); | 
|  | 5528 | } | 
|  | 5529 |  | 
|  | 5530 | void LocationsBuilderX86::VisitUnresolvedInstanceFieldSet( | 
|  | 5531 | HUnresolvedInstanceFieldSet* instruction) { | 
|  | 5532 | FieldAccessCallingConventionX86 calling_convention; | 
|  | 5533 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 5534 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 5535 | } | 
|  | 5536 |  | 
|  | 5537 | void InstructionCodeGeneratorX86::VisitUnresolvedInstanceFieldSet( | 
|  | 5538 | HUnresolvedInstanceFieldSet* instruction) { | 
|  | 5539 | FieldAccessCallingConventionX86 calling_convention; | 
|  | 5540 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 5541 | instruction->GetFieldType(), | 
|  | 5542 | instruction->GetFieldIndex(), | 
|  | 5543 | instruction->GetDexPc(), | 
|  | 5544 | calling_convention); | 
|  | 5545 | } | 
|  | 5546 |  | 
|  | 5547 | void LocationsBuilderX86::VisitUnresolvedStaticFieldGet( | 
|  | 5548 | HUnresolvedStaticFieldGet* instruction) { | 
|  | 5549 | FieldAccessCallingConventionX86 calling_convention; | 
|  | 5550 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 5551 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 5552 | } | 
|  | 5553 |  | 
|  | 5554 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldGet( | 
|  | 5555 | HUnresolvedStaticFieldGet* instruction) { | 
|  | 5556 | FieldAccessCallingConventionX86 calling_convention; | 
|  | 5557 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 5558 | instruction->GetFieldType(), | 
|  | 5559 | instruction->GetFieldIndex(), | 
|  | 5560 | instruction->GetDexPc(), | 
|  | 5561 | calling_convention); | 
|  | 5562 | } | 
|  | 5563 |  | 
|  | 5564 | void LocationsBuilderX86::VisitUnresolvedStaticFieldSet( | 
|  | 5565 | HUnresolvedStaticFieldSet* instruction) { | 
|  | 5566 | FieldAccessCallingConventionX86 calling_convention; | 
|  | 5567 | codegen_->CreateUnresolvedFieldLocationSummary( | 
|  | 5568 | instruction, instruction->GetFieldType(), calling_convention); | 
|  | 5569 | } | 
|  | 5570 |  | 
|  | 5571 | void InstructionCodeGeneratorX86::VisitUnresolvedStaticFieldSet( | 
|  | 5572 | HUnresolvedStaticFieldSet* instruction) { | 
|  | 5573 | FieldAccessCallingConventionX86 calling_convention; | 
|  | 5574 | codegen_->GenerateUnresolvedFieldAccess(instruction, | 
|  | 5575 | instruction->GetFieldType(), | 
|  | 5576 | instruction->GetFieldIndex(), | 
|  | 5577 | instruction->GetDexPc(), | 
|  | 5578 | calling_convention); | 
|  | 5579 | } | 
|  | 5580 |  | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5581 | void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) { | 
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5582 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction); | 
|  | 5583 | Location loc = codegen_->GetCompilerOptions().GetImplicitNullChecks() | 
|  | 5584 | ? Location::RequiresRegister() | 
|  | 5585 | : Location::Any(); | 
|  | 5586 | locations->SetInAt(0, loc); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5587 | } | 
|  | 5588 |  | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5589 | void CodeGeneratorX86::GenerateImplicitNullCheck(HNullCheck* instruction) { | 
|  | 5590 | if (CanMoveNullCheckToUser(instruction)) { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5591 | return; | 
|  | 5592 | } | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5593 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 5594 | Location obj = locations->InAt(0); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5595 |  | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5596 | __ testl(EAX, Address(obj.AsRegister<Register>(), 0)); | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5597 | RecordPcInfo(instruction, instruction->GetDexPc()); | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5598 | } | 
|  | 5599 |  | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5600 | void CodeGeneratorX86::GenerateExplicitNullCheck(HNullCheck* instruction) { | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5601 | SlowPathCode* slow_path = new (GetScopedAllocator()) NullCheckSlowPathX86(instruction); | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5602 | AddSlowPath(slow_path); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5603 |  | 
|  | 5604 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 5605 | Location obj = locations->InAt(0); | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5606 |  | 
|  | 5607 | if (obj.IsRegister()) { | 
| Mark Mendell | 42514f6 | 2015-03-31 11:34:22 -0400 | [diff] [blame] | 5608 | __ testl(obj.AsRegister<Register>(), obj.AsRegister<Register>()); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5609 | } else if (obj.IsStackSlot()) { | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5610 | __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0)); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5611 | } else { | 
|  | 5612 | DCHECK(obj.IsConstant()) << obj; | 
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 5613 | DCHECK(obj.GetConstant()->IsNullConstant()); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5614 | __ jmp(slow_path->GetEntryLabel()); | 
|  | 5615 | return; | 
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5616 | } | 
|  | 5617 | __ j(kEqual, slow_path->GetEntryLabel()); | 
|  | 5618 | } | 
|  | 5619 |  | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5620 | void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) { | 
| Calin Juravle | 2ae4818 | 2016-03-16 14:05:09 +0000 | [diff] [blame] | 5621 | codegen_->GenerateNullCheck(instruction); | 
| Calin Juravle | cd6dffe | 2015-01-08 17:35:35 +0000 | [diff] [blame] | 5622 | } | 
|  | 5623 |  | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5624 | void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5625 | bool object_array_get_with_read_barrier = | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5626 | kEmitCompilerReadBarrier && (instruction->GetType() == DataType::Type::kReference); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5627 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5628 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, | 
|  | 5629 | object_array_get_with_read_barrier | 
|  | 5630 | ? LocationSummary::kCallOnSlowPath | 
|  | 5631 | : LocationSummary::kNoCall); | 
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5632 | if (object_array_get_with_read_barrier && kUseBakerReadBarrier) { | 
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 5633 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty());  // No caller-save registers. | 
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 5634 | } | 
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 5635 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 5636 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5637 | if (DataType::IsFloatingPointType(instruction->GetType())) { | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5638 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); | 
|  | 5639 | } else { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5640 | // The output overlaps in case of long: we don't want the low move | 
|  | 5641 | // to overwrite the array's location.  Likewise, in the case of an | 
|  | 5642 | // object array get with read barriers enabled, we do not want the | 
|  | 5643 | // move to overwrite the array's location, as we need it to emit | 
|  | 5644 | // the read barrier. | 
|  | 5645 | locations->SetOut( | 
|  | 5646 | Location::RequiresRegister(), | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5647 | (instruction->GetType() == DataType::Type::kInt64 || object_array_get_with_read_barrier) | 
|  | 5648 | ? Location::kOutputOverlap | 
|  | 5649 | : Location::kNoOutputOverlap); | 
| Alexandre Rames | 88c13cd | 2015-04-14 17:35:39 +0100 | [diff] [blame] | 5650 | } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5651 | } | 
|  | 5652 |  | 
|  | 5653 | void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { | 
|  | 5654 | LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5655 | Location obj_loc = locations->InAt(0); | 
|  | 5656 | Register obj = obj_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5657 | Location index = locations->InAt(1); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5658 | Location out_loc = locations->Out(); | 
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5659 | uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5660 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5661 | DataType::Type type = instruction->GetType(); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5662 | switch (type) { | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5663 | case DataType::Type::kBool: | 
|  | 5664 | case DataType::Type::kUint8: { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5665 | Register out = out_loc.AsRegister<Register>(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5666 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5667 | break; | 
|  | 5668 | } | 
|  | 5669 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5670 | case DataType::Type::kInt8: { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5671 | Register out = out_loc.AsRegister<Register>(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5672 | __ movsxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5673 | break; | 
|  | 5674 | } | 
|  | 5675 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5676 | case DataType::Type::kUint16: { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5677 | Register out = out_loc.AsRegister<Register>(); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5678 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { | 
|  | 5679 | // Branch cases into compressed and uncompressed for each index's type. | 
|  | 5680 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); | 
|  | 5681 | NearLabel done, not_compressed; | 
| Vladimir Marko | 3c89d42 | 2017-02-17 11:30:23 +0000 | [diff] [blame] | 5682 | __ testb(Address(obj, count_offset), Immediate(1)); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5683 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 5684 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, | 
|  | 5685 | "Expecting 0=compressed, 1=uncompressed"); | 
|  | 5686 | __ j(kNotZero, ¬_compressed); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 5687 | __ movzxb(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_1, data_offset)); | 
|  | 5688 | __ jmp(&done); | 
|  | 5689 | __ Bind(¬_compressed); | 
|  | 5690 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); | 
|  | 5691 | __ Bind(&done); | 
|  | 5692 | } else { | 
|  | 5693 | // Common case for charAt of array of char or when string compression's | 
|  | 5694 | // feature is turned off. | 
|  | 5695 | __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); | 
|  | 5696 | } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5697 | break; | 
|  | 5698 | } | 
|  | 5699 |  | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5700 | case DataType::Type::kInt16: { | 
|  | 5701 | Register out = out_loc.AsRegister<Register>(); | 
|  | 5702 | __ movsxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); | 
|  | 5703 | break; | 
|  | 5704 | } | 
|  | 5705 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5706 | case DataType::Type::kInt32: { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5707 | Register out = out_loc.AsRegister<Register>(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5708 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5709 | break; | 
|  | 5710 | } | 
|  | 5711 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5712 | case DataType::Type::kReference: { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5713 | static_assert( | 
|  | 5714 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), | 
|  | 5715 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5716 | // /* HeapReference<Object> */ out = | 
|  | 5717 | //     *(obj + data_offset + index * sizeof(HeapReference<Object>)) | 
|  | 5718 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5719 | // Note that a potential implicit null check is handled in this | 
|  | 5720 | // CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier call. | 
|  | 5721 | codegen_->GenerateArrayLoadWithBakerReadBarrier( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 5722 | instruction, out_loc, obj, data_offset, index, /* needs_null_check= */ true); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5723 | } else { | 
|  | 5724 | Register out = out_loc.AsRegister<Register>(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5725 | __ movl(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); | 
|  | 5726 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5727 | // If read barriers are enabled, emit read barriers other than | 
|  | 5728 | // Baker's using a slow path (and also unpoison the loaded | 
|  | 5729 | // reference, if heap poisoning is enabled). | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5730 | if (index.IsConstant()) { | 
|  | 5731 | uint32_t offset = | 
|  | 5732 | (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset; | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5733 | codegen_->MaybeGenerateReadBarrierSlow(instruction, out_loc, out_loc, obj_loc, offset); | 
|  | 5734 | } else { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5735 | codegen_->MaybeGenerateReadBarrierSlow( | 
|  | 5736 | instruction, out_loc, out_loc, obj_loc, data_offset, index); | 
|  | 5737 | } | 
|  | 5738 | } | 
|  | 5739 | break; | 
|  | 5740 | } | 
|  | 5741 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5742 | case DataType::Type::kInt64: { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5743 | DCHECK_NE(obj, out_loc.AsRegisterPairLow<Register>()); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5744 | __ movl(out_loc.AsRegisterPairLow<Register>(), | 
|  | 5745 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); | 
|  | 5746 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5747 | __ movl(out_loc.AsRegisterPairHigh<Register>(), | 
|  | 5748 | CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset + kX86WordSize)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5749 | break; | 
|  | 5750 | } | 
|  | 5751 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5752 | case DataType::Type::kFloat32: { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5753 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5754 | __ movss(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset)); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5755 | break; | 
|  | 5756 | } | 
|  | 5757 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5758 | case DataType::Type::kFloat64: { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5759 | XmmRegister out = out_loc.AsFpuRegister<XmmRegister>(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5760 | __ movsd(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_8, data_offset)); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5761 | break; | 
|  | 5762 | } | 
|  | 5763 |  | 
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 5764 | case DataType::Type::kUint32: | 
|  | 5765 | case DataType::Type::kUint64: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5766 | case DataType::Type::kVoid: | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5767 | LOG(FATAL) << "Unreachable type " << type; | 
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 5768 | UNREACHABLE(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5769 | } | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5770 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5771 | if (type == DataType::Type::kReference || type == DataType::Type::kInt64) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 5772 | // Potential implicit null checks, in the case of reference or | 
|  | 5773 | // long arrays, are handled in the previous switch statement. | 
|  | 5774 | } else { | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5775 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5776 | } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5777 | } | 
|  | 5778 |  | 
|  | 5779 | void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5780 | DataType::Type value_type = instruction->GetComponentType(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5781 |  | 
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5782 | bool needs_write_barrier = | 
|  | 5783 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5784 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); | 
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5785 |  | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 5786 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5787 | instruction, | 
| Vladimir Marko | 8d49fd7 | 2016-08-25 15:20:47 +0100 | [diff] [blame] | 5788 | may_need_runtime_call_for_type_check ? | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5789 | LocationSummary::kCallOnSlowPath : | 
|  | 5790 | LocationSummary::kNoCall); | 
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5791 |  | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5792 | bool is_byte_type = DataType::Size(value_type) == 1u; | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5793 | // We need the inputs to be different than the output in case of long operation. | 
|  | 5794 | // In case of a byte operation, the register allocator does not support multiple | 
|  | 5795 | // inputs that die at entry with one in a specific register. | 
|  | 5796 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 5797 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 5798 | if (is_byte_type) { | 
|  | 5799 | // Ensure the value is in a byte register. | 
|  | 5800 | locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2))); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5801 | } else if (DataType::IsFloatingPointType(value_type)) { | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5802 | locations->SetInAt(2, Location::FpuRegisterOrConstant(instruction->InputAt(2))); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5803 | } else { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5804 | locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2))); | 
|  | 5805 | } | 
|  | 5806 | if (needs_write_barrier) { | 
|  | 5807 | // Temporary registers for the write barrier. | 
|  | 5808 | locations->AddTemp(Location::RequiresRegister());  // Possibly used for ref. poisoning too. | 
|  | 5809 | // Ensure the card is in a byte register. | 
| Roland Levillain | 4f6b0b5 | 2015-11-23 19:29:22 +0000 | [diff] [blame] | 5810 | locations->AddTemp(Location::RegisterLocation(ECX)); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5811 | } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5812 | } | 
|  | 5813 |  | 
|  | 5814 | void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) { | 
|  | 5815 | LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5816 | Location array_loc = locations->InAt(0); | 
|  | 5817 | Register array = array_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5818 | Location index = locations->InAt(1); | 
| Nicolas Geoffray | 26a25ef | 2014-09-30 13:54:09 +0100 | [diff] [blame] | 5819 | Location value = locations->InAt(2); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5820 | DataType::Type value_type = instruction->GetComponentType(); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5821 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
|  | 5822 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); | 
|  | 5823 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5824 | bool may_need_runtime_call_for_type_check = instruction->NeedsTypeCheck(); | 
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5825 | bool needs_write_barrier = | 
|  | 5826 | CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue()); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5827 |  | 
|  | 5828 | switch (value_type) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5829 | case DataType::Type::kBool: | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5830 | case DataType::Type::kUint8: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5831 | case DataType::Type::kInt8: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5832 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5833 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_1, offset); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5834 | if (value.IsRegister()) { | 
|  | 5835 | __ movb(address, value.AsRegister<ByteRegister>()); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5836 | } else { | 
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5837 | __ movb(address, Immediate(CodeGenerator::GetInt8ValueOf(value.GetConstant()))); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5838 | } | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5839 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5840 | break; | 
|  | 5841 | } | 
|  | 5842 |  | 
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5843 | case DataType::Type::kUint16: | 
|  | 5844 | case DataType::Type::kInt16: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5845 | uint32_t offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5846 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_2, offset); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5847 | if (value.IsRegister()) { | 
|  | 5848 | __ movw(address, value.AsRegister<Register>()); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5849 | } else { | 
| Nicolas Geoffray | 7861208 | 2017-07-24 14:18:53 +0100 | [diff] [blame] | 5850 | __ movw(address, Immediate(CodeGenerator::GetInt16ValueOf(value.GetConstant()))); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5851 | } | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5852 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5853 | break; | 
|  | 5854 | } | 
|  | 5855 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5856 | case DataType::Type::kReference: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5857 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5858 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5859 |  | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5860 | if (!value.IsRegister()) { | 
|  | 5861 | // Just setting null. | 
|  | 5862 | DCHECK(instruction->InputAt(2)->IsNullConstant()); | 
|  | 5863 | DCHECK(value.IsConstant()) << value; | 
|  | 5864 | __ movl(address, Immediate(0)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5865 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5866 | DCHECK(!needs_write_barrier); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5867 | DCHECK(!may_need_runtime_call_for_type_check); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5868 | break; | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5869 | } | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5870 |  | 
|  | 5871 | DCHECK(needs_write_barrier); | 
|  | 5872 | Register register_value = value.AsRegister<Register>(); | 
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5873 | // We cannot use a NearLabel for `done`, as its range may be too | 
|  | 5874 | // short when Baker read barriers are enabled. | 
|  | 5875 | Label done; | 
|  | 5876 | NearLabel not_null, do_put; | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5877 | SlowPathCode* slow_path = nullptr; | 
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5878 | Location temp_loc = locations->GetTemp(0); | 
|  | 5879 | Register temp = temp_loc.AsRegister<Register>(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5880 | if (may_need_runtime_call_for_type_check) { | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 5881 | slow_path = new (codegen_->GetScopedAllocator()) ArraySetSlowPathX86(instruction); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5882 | codegen_->AddSlowPath(slow_path); | 
|  | 5883 | if (instruction->GetValueCanBeNull()) { | 
|  | 5884 | __ testl(register_value, register_value); | 
|  | 5885 | __ j(kNotEqual, ¬_null); | 
|  | 5886 | __ movl(address, Immediate(0)); | 
|  | 5887 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5888 | __ jmp(&done); | 
|  | 5889 | __ Bind(¬_null); | 
|  | 5890 | } | 
|  | 5891 |  | 
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5892 | // Note that when Baker read barriers are enabled, the type | 
|  | 5893 | // checks are performed without read barriers.  This is fine, | 
|  | 5894 | // even in the case where a class object is in the from-space | 
|  | 5895 | // after the flip, as a comparison involving such a type would | 
|  | 5896 | // not produce a false positive; it may of course produce a | 
|  | 5897 | // false negative, in which case we would take the ArraySet | 
|  | 5898 | // slow path. | 
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5899 |  | 
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5900 | // /* HeapReference<Class> */ temp = array->klass_ | 
|  | 5901 | __ movl(temp, Address(array, class_offset)); | 
|  | 5902 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5903 | __ MaybeUnpoisonHeapReference(temp); | 
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5904 |  | 
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5905 | // /* HeapReference<Class> */ temp = temp->component_type_ | 
|  | 5906 | __ movl(temp, Address(temp, component_offset)); | 
|  | 5907 | // If heap poisoning is enabled, no need to unpoison `temp` | 
|  | 5908 | // nor the object reference in `register_value->klass`, as | 
|  | 5909 | // we are comparing two poisoned references. | 
|  | 5910 | __ cmpl(temp, Address(register_value, class_offset)); | 
| Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 5911 |  | 
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5912 | if (instruction->StaticTypeOfArrayIsObjectArray()) { | 
|  | 5913 | __ j(kEqual, &do_put); | 
|  | 5914 | // If heap poisoning is enabled, the `temp` reference has | 
|  | 5915 | // not been unpoisoned yet; unpoison it now. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5916 | __ MaybeUnpoisonHeapReference(temp); | 
|  | 5917 |  | 
| Roland Levillain | 9d6e1f8 | 2016-09-05 15:57:33 +0100 | [diff] [blame] | 5918 | // If heap poisoning is enabled, no need to unpoison the | 
|  | 5919 | // heap reference loaded below, as it is only used for a | 
|  | 5920 | // comparison with null. | 
|  | 5921 | __ cmpl(Address(temp, super_offset), Immediate(0)); | 
|  | 5922 | __ j(kNotEqual, slow_path->GetEntryLabel()); | 
|  | 5923 | __ Bind(&do_put); | 
|  | 5924 | } else { | 
|  | 5925 | __ j(kNotEqual, slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5926 | } | 
|  | 5927 | } | 
|  | 5928 |  | 
|  | 5929 | if (kPoisonHeapReferences) { | 
|  | 5930 | __ movl(temp, register_value); | 
|  | 5931 | __ PoisonHeapReference(temp); | 
|  | 5932 | __ movl(address, temp); | 
|  | 5933 | } else { | 
|  | 5934 | __ movl(address, register_value); | 
|  | 5935 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5936 | if (!may_need_runtime_call_for_type_check) { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5937 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5938 | } | 
|  | 5939 |  | 
|  | 5940 | Register card = locations->GetTemp(1).AsRegister<Register>(); | 
|  | 5941 | codegen_->MarkGCCard( | 
|  | 5942 | temp, card, array, value.AsRegister<Register>(), instruction->GetValueCanBeNull()); | 
|  | 5943 | __ Bind(&done); | 
|  | 5944 |  | 
|  | 5945 | if (slow_path != nullptr) { | 
|  | 5946 | __ Bind(slow_path->GetExitLabel()); | 
|  | 5947 | } | 
|  | 5948 |  | 
|  | 5949 | break; | 
|  | 5950 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 5951 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5952 | case DataType::Type::kInt32: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5953 | uint32_t offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5954 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5955 | if (value.IsRegister()) { | 
|  | 5956 | __ movl(address, value.AsRegister<Register>()); | 
|  | 5957 | } else { | 
|  | 5958 | DCHECK(value.IsConstant()) << value; | 
|  | 5959 | int32_t v = CodeGenerator::GetInt32ValueOf(value.GetConstant()); | 
|  | 5960 | __ movl(address, Immediate(v)); | 
|  | 5961 | } | 
|  | 5962 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5963 | break; | 
|  | 5964 | } | 
|  | 5965 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5966 | case DataType::Type::kInt64: { | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5967 | uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5968 | if (value.IsRegisterPair()) { | 
|  | 5969 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), | 
|  | 5970 | value.AsRegisterPairLow<Register>()); | 
|  | 5971 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5972 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), | 
|  | 5973 | value.AsRegisterPairHigh<Register>()); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5974 | } else { | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5975 | DCHECK(value.IsConstant()); | 
|  | 5976 | int64_t val = value.GetConstant()->AsLongConstant()->GetValue(); | 
|  | 5977 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset), | 
|  | 5978 | Immediate(Low32Bits(val))); | 
|  | 5979 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 5980 | __ movl(CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, data_offset + kX86WordSize), | 
|  | 5981 | Immediate(High32Bits(val))); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5982 | } | 
|  | 5983 | break; | 
|  | 5984 | } | 
|  | 5985 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5986 | case DataType::Type::kFloat32: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5987 | uint32_t offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 5988 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_4, offset); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 5989 | if (value.IsFpuRegister()) { | 
|  | 5990 | __ movss(address, value.AsFpuRegister<XmmRegister>()); | 
|  | 5991 | } else { | 
|  | 5992 | DCHECK(value.IsConstant()); | 
|  | 5993 | int32_t v = bit_cast<int32_t, float>(value.GetConstant()->AsFloatConstant()->GetValue()); | 
|  | 5994 | __ movl(address, Immediate(v)); | 
|  | 5995 | } | 
|  | 5996 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 5997 | break; | 
|  | 5998 | } | 
|  | 5999 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6000 | case DataType::Type::kFloat64: { | 
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6001 | uint32_t offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value(); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6002 | Address address = CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6003 | if (value.IsFpuRegister()) { | 
|  | 6004 | __ movsd(address, value.AsFpuRegister<XmmRegister>()); | 
|  | 6005 | } else { | 
|  | 6006 | DCHECK(value.IsConstant()); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6007 | Address address_hi = | 
|  | 6008 | CodeGeneratorX86::ArrayAddress(array, index, TIMES_8, offset + kX86WordSize); | 
| Mark Mendell | 8148937 | 2015-11-04 11:30:41 -0500 | [diff] [blame] | 6009 | int64_t v = bit_cast<int64_t, double>(value.GetConstant()->AsDoubleConstant()->GetValue()); | 
|  | 6010 | __ movl(address, Immediate(Low32Bits(v))); | 
|  | 6011 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
|  | 6012 | __ movl(address_hi, Immediate(High32Bits(v))); | 
|  | 6013 | } | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6014 | break; | 
|  | 6015 | } | 
|  | 6016 |  | 
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 6017 | case DataType::Type::kUint32: | 
|  | 6018 | case DataType::Type::kUint64: | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6019 | case DataType::Type::kVoid: | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6020 | LOG(FATAL) << "Unreachable type " << instruction->GetType(); | 
| Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 6021 | UNREACHABLE(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6022 | } | 
|  | 6023 | } | 
|  | 6024 |  | 
|  | 6025 | void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6026 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); | 
| Nicolas Geoffray | 8e3964b | 2014-10-17 11:06:38 +0100 | [diff] [blame] | 6027 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6028 | if (!instruction->IsEmittedAtUseSite()) { | 
|  | 6029 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 6030 | } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6031 | } | 
|  | 6032 |  | 
|  | 6033 | void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) { | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6034 | if (instruction->IsEmittedAtUseSite()) { | 
|  | 6035 | return; | 
|  | 6036 | } | 
|  | 6037 |  | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6038 | LocationSummary* locations = instruction->GetLocations(); | 
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6039 | uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6040 | Register obj = locations->InAt(0).AsRegister<Register>(); | 
|  | 6041 | Register out = locations->Out().AsRegister<Register>(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6042 | __ movl(out, Address(obj, offset)); | 
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6043 | codegen_->MaybeRecordImplicitNullCheck(instruction); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6044 | // Mask out most significant bit in case the array is String's array of char. | 
|  | 6045 | if (mirror::kUseStringCompression && instruction->IsStringLength()) { | 
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6046 | __ shrl(out, Immediate(1)); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6047 | } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6048 | } | 
|  | 6049 |  | 
|  | 6050 | void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) { | 
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6051 | RegisterSet caller_saves = RegisterSet::Empty(); | 
|  | 6052 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 6053 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 6054 | caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); | 
|  | 6055 | LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves); | 
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6056 | locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0))); | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6057 | HInstruction* length = instruction->InputAt(1); | 
|  | 6058 | if (!length->IsEmittedAtUseSite()) { | 
|  | 6059 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); | 
|  | 6060 | } | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6061 | // Need register to see array's length. | 
|  | 6062 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { | 
|  | 6063 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 6064 | } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6065 | } | 
|  | 6066 |  | 
|  | 6067 | void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) { | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6068 | const bool is_string_compressed_char_at = | 
|  | 6069 | mirror::kUseStringCompression && instruction->IsStringCharAt(); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6070 | LocationSummary* locations = instruction->GetLocations(); | 
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6071 | Location index_loc = locations->InAt(0); | 
|  | 6072 | Location length_loc = locations->InAt(1); | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6073 | SlowPathCode* slow_path = | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6074 | new (codegen_->GetScopedAllocator()) BoundsCheckSlowPathX86(instruction); | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6075 |  | 
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6076 | if (length_loc.IsConstant()) { | 
|  | 6077 | int32_t length = CodeGenerator::GetInt32ValueOf(length_loc.GetConstant()); | 
|  | 6078 | if (index_loc.IsConstant()) { | 
|  | 6079 | // BCE will remove the bounds check if we are guarenteed to pass. | 
|  | 6080 | int32_t index = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); | 
|  | 6081 | if (index < 0 || index >= length) { | 
|  | 6082 | codegen_->AddSlowPath(slow_path); | 
|  | 6083 | __ jmp(slow_path->GetEntryLabel()); | 
|  | 6084 | } else { | 
|  | 6085 | // Some optimization after BCE may have generated this, and we should not | 
|  | 6086 | // generate a bounds check if it is a valid range. | 
|  | 6087 | } | 
|  | 6088 | return; | 
|  | 6089 | } | 
|  | 6090 |  | 
|  | 6091 | // We have to reverse the jump condition because the length is the constant. | 
|  | 6092 | Register index_reg = index_loc.AsRegister<Register>(); | 
|  | 6093 | __ cmpl(index_reg, Immediate(length)); | 
|  | 6094 | codegen_->AddSlowPath(slow_path); | 
|  | 6095 | __ j(kAboveEqual, slow_path->GetEntryLabel()); | 
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6096 | } else { | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6097 | HInstruction* array_length = instruction->InputAt(1); | 
|  | 6098 | if (array_length->IsEmittedAtUseSite()) { | 
|  | 6099 | // Address the length field in the array. | 
|  | 6100 | DCHECK(array_length->IsArrayLength()); | 
|  | 6101 | uint32_t len_offset = CodeGenerator::GetArrayLengthOffset(array_length->AsArrayLength()); | 
|  | 6102 | Location array_loc = array_length->GetLocations()->InAt(0); | 
|  | 6103 | Address array_len(array_loc.AsRegister<Register>(), len_offset); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6104 | if (is_string_compressed_char_at) { | 
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6105 | // TODO: if index_loc.IsConstant(), compare twice the index (to compensate for | 
|  | 6106 | // the string compression flag) with the in-memory length and avoid the temporary. | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6107 | Register length_reg = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 6108 | __ movl(length_reg, array_len); | 
|  | 6109 | codegen_->MaybeRecordImplicitNullCheck(array_length); | 
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 6110 | __ shrl(length_reg, Immediate(1)); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6111 | codegen_->GenerateIntCompare(length_reg, index_loc); | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6112 | } else { | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 6113 | // Checking bounds for general case: | 
|  | 6114 | // Array of char or string's array with feature compression off. | 
|  | 6115 | if (index_loc.IsConstant()) { | 
|  | 6116 | int32_t value = CodeGenerator::GetInt32ValueOf(index_loc.GetConstant()); | 
|  | 6117 | __ cmpl(array_len, Immediate(value)); | 
|  | 6118 | } else { | 
|  | 6119 | __ cmpl(array_len, index_loc.AsRegister<Register>()); | 
|  | 6120 | } | 
|  | 6121 | codegen_->MaybeRecordImplicitNullCheck(array_length); | 
| Mark Mendell | ee8d971 | 2016-07-12 11:13:15 -0400 | [diff] [blame] | 6122 | } | 
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6123 | } else { | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 6124 | codegen_->GenerateIntCompare(length_loc, index_loc); | 
| Mark Mendell | 99dbd68 | 2015-04-22 16:18:52 -0400 | [diff] [blame] | 6125 | } | 
|  | 6126 | codegen_->AddSlowPath(slow_path); | 
|  | 6127 | __ j(kBelowEqual, slow_path->GetEntryLabel()); | 
| Mark Mendell | f60c90b | 2015-03-04 15:12:59 -0500 | [diff] [blame] | 6128 | } | 
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6129 | } | 
|  | 6130 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6131 | void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) { | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6132 | LOG(FATAL) << "Unreachable"; | 
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6133 | } | 
|  | 6134 |  | 
|  | 6135 | void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) { | 
| Vladimir Marko | bea75ff | 2017-10-11 20:39:54 +0100 | [diff] [blame] | 6136 | if (instruction->GetNext()->IsSuspendCheck() && | 
|  | 6137 | instruction->GetBlock()->GetLoopInformation() != nullptr) { | 
|  | 6138 | HSuspendCheck* suspend_check = instruction->GetNext()->AsSuspendCheck(); | 
|  | 6139 | // The back edge will generate the suspend check. | 
|  | 6140 | codegen_->ClearSpillSlotsFromLoopPhisInStackMap(suspend_check, instruction); | 
|  | 6141 | } | 
|  | 6142 |  | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6143 | codegen_->GetMoveResolver()->EmitNativeCode(instruction); | 
|  | 6144 | } | 
|  | 6145 |  | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6146 | void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6147 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( | 
|  | 6148 | instruction, LocationSummary::kCallOnSlowPath); | 
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 6149 | // In suspend check slow path, usually there are no caller-save registers at all. | 
|  | 6150 | // If SIMD instructions are present, however, we force spilling all live SIMD | 
|  | 6151 | // registers in full width (since the runtime only saves/restores lower part). | 
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6152 | locations->SetCustomSlowPathCallerSaves( | 
|  | 6153 | GetGraph()->HasSIMD() ? RegisterSet::AllFpu() : RegisterSet::Empty()); | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6154 | } | 
|  | 6155 |  | 
|  | 6156 | void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) { | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6157 | HBasicBlock* block = instruction->GetBlock(); | 
|  | 6158 | if (block->GetLoopInformation() != nullptr) { | 
|  | 6159 | DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction); | 
|  | 6160 | // The back edge will generate the suspend check. | 
|  | 6161 | return; | 
|  | 6162 | } | 
|  | 6163 | if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) { | 
|  | 6164 | // The goto will generate the suspend check. | 
|  | 6165 | return; | 
|  | 6166 | } | 
|  | 6167 | GenerateSuspendCheck(instruction, nullptr); | 
|  | 6168 | } | 
|  | 6169 |  | 
|  | 6170 | void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction, | 
|  | 6171 | HBasicBlock* successor) { | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6172 | SuspendCheckSlowPathX86* slow_path = | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6173 | down_cast<SuspendCheckSlowPathX86*>(instruction->GetSlowPath()); | 
|  | 6174 | if (slow_path == nullptr) { | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6175 | slow_path = | 
|  | 6176 | new (codegen_->GetScopedAllocator()) SuspendCheckSlowPathX86(instruction, successor); | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6177 | instruction->SetSlowPath(slow_path); | 
|  | 6178 | codegen_->AddSlowPath(slow_path); | 
|  | 6179 | if (successor != nullptr) { | 
|  | 6180 | DCHECK(successor->IsLoopHeader()); | 
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6181 | } | 
|  | 6182 | } else { | 
|  | 6183 | DCHECK_EQ(slow_path->GetSuccessor(), successor); | 
|  | 6184 | } | 
|  | 6185 |  | 
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6186 | __ fs()->cmpw(Address::Absolute(Thread::ThreadFlagsOffset<kX86PointerSize>().Int32Value()), | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6187 | Immediate(0)); | 
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 6188 | if (successor == nullptr) { | 
|  | 6189 | __ j(kNotEqual, slow_path->GetEntryLabel()); | 
|  | 6190 | __ Bind(slow_path->GetReturnLabel()); | 
|  | 6191 | } else { | 
|  | 6192 | __ j(kEqual, codegen_->GetLabelOf(successor)); | 
|  | 6193 | __ jmp(slow_path->GetEntryLabel()); | 
|  | 6194 | } | 
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6195 | } | 
|  | 6196 |  | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6197 | X86Assembler* ParallelMoveResolverX86::GetAssembler() const { | 
|  | 6198 | return codegen_->GetAssembler(); | 
|  | 6199 | } | 
|  | 6200 |  | 
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6201 | void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src, int number_of_words) { | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6202 | ScratchRegisterScope ensure_scratch( | 
|  | 6203 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); | 
|  | 6204 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); | 
|  | 6205 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6206 |  | 
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6207 | // Now that temp register is available (possibly spilled), move blocks of memory. | 
|  | 6208 | for (int i = 0; i < number_of_words; i++) { | 
|  | 6209 | __ movl(temp_reg, Address(ESP, src + stack_offset)); | 
|  | 6210 | __ movl(Address(ESP, dst + stack_offset), temp_reg); | 
|  | 6211 | stack_offset += kX86WordSize; | 
|  | 6212 | } | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6213 | } | 
|  | 6214 |  | 
|  | 6215 | void ParallelMoveResolverX86::EmitMove(size_t index) { | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6216 | MoveOperands* move = moves_[index]; | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6217 | Location source = move->GetSource(); | 
|  | 6218 | Location destination = move->GetDestination(); | 
|  | 6219 |  | 
|  | 6220 | if (source.IsRegister()) { | 
|  | 6221 | if (destination.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6222 | __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6223 | } else if (destination.IsFpuRegister()) { | 
|  | 6224 | __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6225 | } else { | 
|  | 6226 | DCHECK(destination.IsStackSlot()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6227 | __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6228 | } | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6229 | } else if (source.IsRegisterPair()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6230 | size_t elem_size = DataType::Size(DataType::Type::kInt32); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6231 | // Create stack space for 2 elements. | 
|  | 6232 | __ subl(ESP, Immediate(2 * elem_size)); | 
|  | 6233 | __ movl(Address(ESP, 0), source.AsRegisterPairLow<Register>()); | 
|  | 6234 | __ movl(Address(ESP, elem_size), source.AsRegisterPairHigh<Register>()); | 
|  | 6235 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, 0)); | 
|  | 6236 | // And remove the temporary stack space we allocated. | 
|  | 6237 | __ addl(ESP, Immediate(2 * elem_size)); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6238 | } else if (source.IsFpuRegister()) { | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6239 | if (destination.IsRegister()) { | 
|  | 6240 | __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>()); | 
|  | 6241 | } else if (destination.IsFpuRegister()) { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6242 | __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6243 | } else if (destination.IsRegisterPair()) { | 
|  | 6244 | XmmRegister src_reg = source.AsFpuRegister<XmmRegister>(); | 
|  | 6245 | __ movd(destination.AsRegisterPairLow<Register>(), src_reg); | 
|  | 6246 | __ psrlq(src_reg, Immediate(32)); | 
|  | 6247 | __ movd(destination.AsRegisterPairHigh<Register>(), src_reg); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6248 | } else if (destination.IsStackSlot()) { | 
|  | 6249 | __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); | 
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6250 | } else if (destination.IsDoubleStackSlot()) { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6251 | __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); | 
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6252 | } else { | 
|  | 6253 | DCHECK(destination.IsSIMDStackSlot()); | 
|  | 6254 | __ movups(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>()); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6255 | } | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6256 | } else if (source.IsStackSlot()) { | 
|  | 6257 | if (destination.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6258 | __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex())); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6259 | } else if (destination.IsFpuRegister()) { | 
|  | 6260 | __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6261 | } else { | 
|  | 6262 | DCHECK(destination.IsStackSlot()); | 
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6263 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6264 | } | 
|  | 6265 | } else if (source.IsDoubleStackSlot()) { | 
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6266 | if (destination.IsRegisterPair()) { | 
|  | 6267 | __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex())); | 
|  | 6268 | __ movl(destination.AsRegisterPairHigh<Register>(), | 
|  | 6269 | Address(ESP, source.GetHighStackIndex(kX86WordSize))); | 
|  | 6270 | } else if (destination.IsFpuRegister()) { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6271 | __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); | 
|  | 6272 | } else { | 
|  | 6273 | DCHECK(destination.IsDoubleStackSlot()) << destination; | 
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6274 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6275 | } | 
| Aart Bik | 5576f37 | 2017-03-23 16:17:37 -0700 | [diff] [blame] | 6276 | } else if (source.IsSIMDStackSlot()) { | 
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6277 | if (destination.IsFpuRegister()) { | 
|  | 6278 | __ movups(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex())); | 
|  | 6279 | } else { | 
|  | 6280 | DCHECK(destination.IsSIMDStackSlot()); | 
|  | 6281 | MoveMemoryToMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); | 
|  | 6282 | } | 
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6283 | } else if (source.IsConstant()) { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6284 | HConstant* constant = source.GetConstant(); | 
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 6285 | if (constant->IsIntConstant() || constant->IsNullConstant()) { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6286 | int32_t value = CodeGenerator::GetInt32ValueOf(constant); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6287 | if (destination.IsRegister()) { | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6288 | if (value == 0) { | 
|  | 6289 | __ xorl(destination.AsRegister<Register>(), destination.AsRegister<Register>()); | 
|  | 6290 | } else { | 
|  | 6291 | __ movl(destination.AsRegister<Register>(), Immediate(value)); | 
|  | 6292 | } | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6293 | } else { | 
|  | 6294 | DCHECK(destination.IsStackSlot()) << destination; | 
| Mark Mendell | 09b8463 | 2015-02-13 17:48:38 -0500 | [diff] [blame] | 6295 | __ movl(Address(ESP, destination.GetStackIndex()), Immediate(value)); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6296 | } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6297 | } else if (constant->IsFloatConstant()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6298 | float fp_value = constant->AsFloatConstant()->GetValue(); | 
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6299 | int32_t value = bit_cast<int32_t, float>(fp_value); | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6300 | Immediate imm(value); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6301 | if (destination.IsFpuRegister()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6302 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); | 
|  | 6303 | if (value == 0) { | 
|  | 6304 | // Easy handling of 0.0. | 
|  | 6305 | __ xorps(dest, dest); | 
|  | 6306 | } else { | 
|  | 6307 | ScratchRegisterScope ensure_scratch( | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6308 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); | 
|  | 6309 | Register temp = static_cast<Register>(ensure_scratch.GetRegister()); | 
|  | 6310 | __ movl(temp, Immediate(value)); | 
|  | 6311 | __ movd(dest, temp); | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 6312 | } | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6313 | } else { | 
|  | 6314 | DCHECK(destination.IsStackSlot()) << destination; | 
|  | 6315 | __ movl(Address(ESP, destination.GetStackIndex()), imm); | 
|  | 6316 | } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6317 | } else if (constant->IsLongConstant()) { | 
|  | 6318 | int64_t value = constant->AsLongConstant()->GetValue(); | 
|  | 6319 | int32_t low_value = Low32Bits(value); | 
|  | 6320 | int32_t high_value = High32Bits(value); | 
|  | 6321 | Immediate low(low_value); | 
|  | 6322 | Immediate high(high_value); | 
|  | 6323 | if (destination.IsDoubleStackSlot()) { | 
|  | 6324 | __ movl(Address(ESP, destination.GetStackIndex()), low); | 
|  | 6325 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); | 
|  | 6326 | } else { | 
|  | 6327 | __ movl(destination.AsRegisterPairLow<Register>(), low); | 
|  | 6328 | __ movl(destination.AsRegisterPairHigh<Register>(), high); | 
|  | 6329 | } | 
|  | 6330 | } else { | 
|  | 6331 | DCHECK(constant->IsDoubleConstant()); | 
|  | 6332 | double dbl_value = constant->AsDoubleConstant()->GetValue(); | 
| Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 6333 | int64_t value = bit_cast<int64_t, double>(dbl_value); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6334 | int32_t low_value = Low32Bits(value); | 
|  | 6335 | int32_t high_value = High32Bits(value); | 
|  | 6336 | Immediate low(low_value); | 
|  | 6337 | Immediate high(high_value); | 
|  | 6338 | if (destination.IsFpuRegister()) { | 
|  | 6339 | XmmRegister dest = destination.AsFpuRegister<XmmRegister>(); | 
|  | 6340 | if (value == 0) { | 
|  | 6341 | // Easy handling of 0.0. | 
|  | 6342 | __ xorpd(dest, dest); | 
|  | 6343 | } else { | 
|  | 6344 | __ pushl(high); | 
|  | 6345 | __ pushl(low); | 
|  | 6346 | __ movsd(dest, Address(ESP, 0)); | 
|  | 6347 | __ addl(ESP, Immediate(8)); | 
|  | 6348 | } | 
|  | 6349 | } else { | 
|  | 6350 | DCHECK(destination.IsDoubleStackSlot()) << destination; | 
|  | 6351 | __ movl(Address(ESP, destination.GetStackIndex()), low); | 
|  | 6352 | __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)), high); | 
|  | 6353 | } | 
| Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 6354 | } | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6355 | } else { | 
| Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6356 | LOG(FATAL) << "Unimplemented move: " << destination << " <- " << source; | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6357 | } | 
|  | 6358 | } | 
|  | 6359 |  | 
| Mark Mendell | a5c19ce | 2015-04-01 12:51:05 -0400 | [diff] [blame] | 6360 | void ParallelMoveResolverX86::Exchange(Register reg, int mem) { | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6361 | Register suggested_scratch = reg == EAX ? EBX : EAX; | 
|  | 6362 | ScratchRegisterScope ensure_scratch( | 
|  | 6363 | this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters()); | 
|  | 6364 |  | 
|  | 6365 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; | 
|  | 6366 | __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset)); | 
|  | 6367 | __ movl(Address(ESP, mem + stack_offset), reg); | 
|  | 6368 | __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister())); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6369 | } | 
|  | 6370 |  | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6371 | void ParallelMoveResolverX86::Exchange32(XmmRegister reg, int mem) { | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6372 | ScratchRegisterScope ensure_scratch( | 
|  | 6373 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); | 
|  | 6374 |  | 
|  | 6375 | Register temp_reg = static_cast<Register>(ensure_scratch.GetRegister()); | 
|  | 6376 | int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0; | 
|  | 6377 | __ movl(temp_reg, Address(ESP, mem + stack_offset)); | 
|  | 6378 | __ movss(Address(ESP, mem + stack_offset), reg); | 
|  | 6379 | __ movd(reg, temp_reg); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6380 | } | 
|  | 6381 |  | 
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6382 | void ParallelMoveResolverX86::Exchange128(XmmRegister reg, int mem) { | 
|  | 6383 | size_t extra_slot = 4 * kX86WordSize; | 
|  | 6384 | __ subl(ESP, Immediate(extra_slot)); | 
|  | 6385 | __ movups(Address(ESP, 0), XmmRegister(reg)); | 
|  | 6386 | ExchangeMemory(0, mem + extra_slot, 4); | 
|  | 6387 | __ movups(XmmRegister(reg), Address(ESP, 0)); | 
|  | 6388 | __ addl(ESP, Immediate(extra_slot)); | 
|  | 6389 | } | 
|  | 6390 |  | 
|  | 6391 | void ParallelMoveResolverX86::ExchangeMemory(int mem1, int mem2, int number_of_words) { | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6392 | ScratchRegisterScope ensure_scratch1( | 
|  | 6393 | this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters()); | 
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6394 |  | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6395 | Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX; | 
|  | 6396 | ScratchRegisterScope ensure_scratch2( | 
|  | 6397 | this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters()); | 
| Nicolas Geoffray | e27f31a | 2014-06-12 17:53:14 +0100 | [diff] [blame] | 6398 |  | 
| Guillaume Sanchez | e14590b | 2015-04-15 18:57:27 +0000 | [diff] [blame] | 6399 | int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0; | 
|  | 6400 | stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0; | 
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6401 |  | 
|  | 6402 | // Now that temp registers are available (possibly spilled), exchange blocks of memory. | 
|  | 6403 | for (int i = 0; i < number_of_words; i++) { | 
|  | 6404 | __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset)); | 
|  | 6405 | __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset)); | 
|  | 6406 | __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister())); | 
|  | 6407 | __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister())); | 
|  | 6408 | stack_offset += kX86WordSize; | 
|  | 6409 | } | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6410 | } | 
|  | 6411 |  | 
|  | 6412 | void ParallelMoveResolverX86::EmitSwap(size_t index) { | 
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6413 | MoveOperands* move = moves_[index]; | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6414 | Location source = move->GetSource(); | 
|  | 6415 | Location destination = move->GetDestination(); | 
|  | 6416 |  | 
|  | 6417 | if (source.IsRegister() && destination.IsRegister()) { | 
| Mark Mendell | 9097981 | 2015-07-28 16:41:21 -0400 | [diff] [blame] | 6418 | // Use XOR swap algorithm to avoid serializing XCHG instruction or using a temporary. | 
|  | 6419 | DCHECK_NE(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
|  | 6420 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
|  | 6421 | __ xorl(source.AsRegister<Register>(), destination.AsRegister<Register>()); | 
|  | 6422 | __ xorl(destination.AsRegister<Register>(), source.AsRegister<Register>()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6423 | } else if (source.IsRegister() && destination.IsStackSlot()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6424 | Exchange(source.AsRegister<Register>(), destination.GetStackIndex()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6425 | } else if (source.IsStackSlot() && destination.IsRegister()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 6426 | Exchange(destination.AsRegister<Register>(), source.GetStackIndex()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6427 | } else if (source.IsStackSlot() && destination.IsStackSlot()) { | 
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6428 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 1); | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6429 | } else if (source.IsFpuRegister() && destination.IsFpuRegister()) { | 
|  | 6430 | // Use XOR Swap algorithm to avoid a temporary. | 
|  | 6431 | DCHECK_NE(source.reg(), destination.reg()); | 
|  | 6432 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
|  | 6433 | __ xorpd(source.AsFpuRegister<XmmRegister>(), destination.AsFpuRegister<XmmRegister>()); | 
|  | 6434 | __ xorpd(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>()); | 
|  | 6435 | } else if (source.IsFpuRegister() && destination.IsStackSlot()) { | 
|  | 6436 | Exchange32(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); | 
|  | 6437 | } else if (destination.IsFpuRegister() && source.IsStackSlot()) { | 
|  | 6438 | Exchange32(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6439 | } else if (source.IsFpuRegister() && destination.IsDoubleStackSlot()) { | 
|  | 6440 | // Take advantage of the 16 bytes in the XMM register. | 
|  | 6441 | XmmRegister reg = source.AsFpuRegister<XmmRegister>(); | 
|  | 6442 | Address stack(ESP, destination.GetStackIndex()); | 
|  | 6443 | // Load the double into the high doubleword. | 
|  | 6444 | __ movhpd(reg, stack); | 
|  | 6445 |  | 
|  | 6446 | // Store the low double into the destination. | 
|  | 6447 | __ movsd(stack, reg); | 
|  | 6448 |  | 
|  | 6449 | // Move the high double to the low double. | 
|  | 6450 | __ psrldq(reg, Immediate(8)); | 
|  | 6451 | } else if (destination.IsFpuRegister() && source.IsDoubleStackSlot()) { | 
|  | 6452 | // Take advantage of the 16 bytes in the XMM register. | 
|  | 6453 | XmmRegister reg = destination.AsFpuRegister<XmmRegister>(); | 
|  | 6454 | Address stack(ESP, source.GetStackIndex()); | 
|  | 6455 | // Load the double into the high doubleword. | 
|  | 6456 | __ movhpd(reg, stack); | 
|  | 6457 |  | 
|  | 6458 | // Store the low double into the destination. | 
|  | 6459 | __ movsd(stack, reg); | 
|  | 6460 |  | 
|  | 6461 | // Move the high double to the low double. | 
|  | 6462 | __ psrldq(reg, Immediate(8)); | 
|  | 6463 | } else if (destination.IsDoubleStackSlot() && source.IsDoubleStackSlot()) { | 
| Aart Bik | cfe50bb | 2017-12-12 14:54:12 -0800 | [diff] [blame] | 6464 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 2); | 
|  | 6465 | } else if (source.IsSIMDStackSlot() && destination.IsSIMDStackSlot()) { | 
|  | 6466 | ExchangeMemory(destination.GetStackIndex(), source.GetStackIndex(), 4); | 
|  | 6467 | } else if (source.IsFpuRegister() && destination.IsSIMDStackSlot()) { | 
|  | 6468 | Exchange128(source.AsFpuRegister<XmmRegister>(), destination.GetStackIndex()); | 
|  | 6469 | } else if (destination.IsFpuRegister() && source.IsSIMDStackSlot()) { | 
|  | 6470 | Exchange128(destination.AsFpuRegister<XmmRegister>(), source.GetStackIndex()); | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6471 | } else { | 
| Mark Mendell | 7c8d009 | 2015-01-26 11:21:33 -0500 | [diff] [blame] | 6472 | LOG(FATAL) << "Unimplemented: source: " << source << ", destination: " << destination; | 
| Nicolas Geoffray | 86dbb9a | 2014-06-04 11:12:39 +0100 | [diff] [blame] | 6473 | } | 
|  | 6474 | } | 
|  | 6475 |  | 
|  | 6476 | void ParallelMoveResolverX86::SpillScratch(int reg) { | 
|  | 6477 | __ pushl(static_cast<Register>(reg)); | 
|  | 6478 | } | 
|  | 6479 |  | 
|  | 6480 | void ParallelMoveResolverX86::RestoreScratch(int reg) { | 
|  | 6481 | __ popl(static_cast<Register>(reg)); | 
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6482 | } | 
|  | 6483 |  | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6484 | HLoadClass::LoadKind CodeGeneratorX86::GetSupportedLoadClassKind( | 
|  | 6485 | HLoadClass::LoadKind desired_class_load_kind) { | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6486 | switch (desired_class_load_kind) { | 
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6487 | case HLoadClass::LoadKind::kInvalid: | 
|  | 6488 | LOG(FATAL) << "UNREACHABLE"; | 
|  | 6489 | UNREACHABLE(); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6490 | case HLoadClass::LoadKind::kReferrersClass: | 
|  | 6491 | break; | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6492 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6493 | case HLoadClass::LoadKind::kBootImageRelRo: | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6494 | case HLoadClass::LoadKind::kBssEntry: | 
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6495 | DCHECK(!Runtime::Current()->UseJitCompilation()); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6496 | break; | 
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6497 | case HLoadClass::LoadKind::kJitBootImageAddress: | 
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6498 | case HLoadClass::LoadKind::kJitTableAddress: | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6499 | DCHECK(Runtime::Current()->UseJitCompilation()); | 
|  | 6500 | break; | 
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6501 | case HLoadClass::LoadKind::kRuntimeCall: | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6502 | break; | 
|  | 6503 | } | 
|  | 6504 | return desired_class_load_kind; | 
|  | 6505 | } | 
|  | 6506 |  | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6507 | void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) { | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6508 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); | 
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6509 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6510 | InvokeRuntimeCallingConvention calling_convention; | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6511 | CodeGenerator::CreateLoadClassRuntimeCallLocationSummary( | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6512 | cls, | 
|  | 6513 | Location::RegisterLocation(calling_convention.GetRegisterAt(0)), | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6514 | Location::RegisterLocation(EAX)); | 
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6515 | DCHECK_EQ(calling_convention.GetRegisterAt(0), EAX); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6516 | return; | 
|  | 6517 | } | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6518 | DCHECK(!cls->NeedsAccessCheck()); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6519 |  | 
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6520 | const bool requires_read_barrier = kEmitCompilerReadBarrier && !cls->IsInBootImage(); | 
|  | 6521 | LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || requires_read_barrier) | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6522 | ? LocationSummary::kCallOnSlowPath | 
|  | 6523 | : LocationSummary::kNoCall; | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6524 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(cls, call_kind); | 
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6525 | if (kUseBakerReadBarrier && requires_read_barrier && !cls->NeedsEnvironment()) { | 
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6526 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty());  // No caller-save registers. | 
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6527 | } | 
|  | 6528 |  | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6529 | if (load_kind == HLoadClass::LoadKind::kReferrersClass || | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6530 | load_kind == HLoadClass::LoadKind::kBootImageLinkTimePcRelative || | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6531 | load_kind == HLoadClass::LoadKind::kBootImageRelRo || | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6532 | load_kind == HLoadClass::LoadKind::kBssEntry) { | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6533 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 6534 | } | 
|  | 6535 | locations->SetOut(Location::RequiresRegister()); | 
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6536 | if (load_kind == HLoadClass::LoadKind::kBssEntry) { | 
|  | 6537 | if (!kUseReadBarrier || kUseBakerReadBarrier) { | 
|  | 6538 | // Rely on the type resolution and/or initialization to save everything. | 
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6539 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); | 
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6540 | } else { | 
|  | 6541 | // For non-Baker read barrier we have a temp-clobbering call. | 
|  | 6542 | } | 
|  | 6543 | } | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6544 | } | 
|  | 6545 |  | 
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6546 | Label* CodeGeneratorX86::NewJitRootClassPatch(const DexFile& dex_file, | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6547 | dex::TypeIndex type_index, | 
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6548 | Handle<mirror::Class> handle) { | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6549 | ReserveJitClassRoot(TypeReference(&dex_file, type_index), handle); | 
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6550 | // Add a patch entry and return the label. | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6551 | jit_class_patches_.emplace_back(&dex_file, type_index.index_); | 
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6552 | PatchInfo<Label>* info = &jit_class_patches_.back(); | 
|  | 6553 | return &info->label; | 
|  | 6554 | } | 
|  | 6555 |  | 
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6556 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not | 
|  | 6557 | // move. | 
|  | 6558 | void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) NO_THREAD_SAFETY_ANALYSIS { | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6559 | HLoadClass::LoadKind load_kind = cls->GetLoadKind(); | 
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6560 | if (load_kind == HLoadClass::LoadKind::kRuntimeCall) { | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6561 | codegen_->GenerateLoadClassRuntimeCall(cls); | 
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6562 | return; | 
|  | 6563 | } | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6564 | DCHECK(!cls->NeedsAccessCheck()); | 
| Calin Juravle | 580b609 | 2015-10-06 17:35:58 +0100 | [diff] [blame] | 6565 |  | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6566 | LocationSummary* locations = cls->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6567 | Location out_loc = locations->Out(); | 
|  | 6568 | Register out = out_loc.AsRegister<Register>(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6569 |  | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6570 | bool generate_null_check = false; | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6571 | const ReadBarrierOption read_barrier_option = cls->IsInBootImage() | 
|  | 6572 | ? kWithoutReadBarrier | 
|  | 6573 | : kCompilerReadBarrierOption; | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6574 | switch (load_kind) { | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6575 | case HLoadClass::LoadKind::kReferrersClass: { | 
|  | 6576 | DCHECK(!cls->CanCallRuntime()); | 
|  | 6577 | DCHECK(!cls->MustGenerateClinitCheck()); | 
|  | 6578 | // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_ | 
|  | 6579 | Register current_method = locations->InAt(0).AsRegister<Register>(); | 
|  | 6580 | GenerateGcRootFieldLoad( | 
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6581 | cls, | 
|  | 6582 | out_loc, | 
|  | 6583 | Address(current_method, ArtMethod::DeclaringClassOffset().Int32Value()), | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 6584 | /* fixup_label= */ nullptr, | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6585 | read_barrier_option); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6586 | break; | 
|  | 6587 | } | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6588 | case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: { | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6589 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6590 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6591 | Register method_address = locations->InAt(0).AsRegister<Register>(); | 
|  | 6592 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6593 | codegen_->RecordBootImageTypePatch(cls); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6594 | break; | 
|  | 6595 | } | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6596 | case HLoadClass::LoadKind::kBootImageRelRo: { | 
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6597 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); | 
|  | 6598 | Register method_address = locations->InAt(0).AsRegister<Register>(); | 
|  | 6599 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6600 | codegen_->RecordBootImageRelRoPatch(cls->InputAt(0)->AsX86ComputeBaseMethodAddress(), | 
|  | 6601 | codegen_->GetBootImageOffset(cls)); | 
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6602 | break; | 
|  | 6603 | } | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6604 | case HLoadClass::LoadKind::kBssEntry: { | 
|  | 6605 | Register method_address = locations->InAt(0).AsRegister<Register>(); | 
|  | 6606 | Address address(method_address, CodeGeneratorX86::kDummy32BitOffset); | 
|  | 6607 | Label* fixup_label = codegen_->NewTypeBssEntryPatch(cls); | 
|  | 6608 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); | 
|  | 6609 | generate_null_check = true; | 
|  | 6610 | break; | 
|  | 6611 | } | 
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6612 | case HLoadClass::LoadKind::kJitBootImageAddress: { | 
|  | 6613 | DCHECK_EQ(read_barrier_option, kWithoutReadBarrier); | 
|  | 6614 | uint32_t address = reinterpret_cast32<uint32_t>(cls->GetClass().Get()); | 
|  | 6615 | DCHECK_NE(address, 0u); | 
|  | 6616 | __ movl(out, Immediate(address)); | 
|  | 6617 | break; | 
|  | 6618 | } | 
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6619 | case HLoadClass::LoadKind::kJitTableAddress: { | 
|  | 6620 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); | 
|  | 6621 | Label* fixup_label = codegen_->NewJitRootClassPatch( | 
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6622 | cls->GetDexFile(), cls->GetTypeIndex(), cls->GetClass()); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6623 | // /* GcRoot<mirror::Class> */ out = *address | 
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6624 | GenerateGcRootFieldLoad(cls, out_loc, address, fixup_label, read_barrier_option); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6625 | break; | 
|  | 6626 | } | 
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6627 | case HLoadClass::LoadKind::kRuntimeCall: | 
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6628 | case HLoadClass::LoadKind::kInvalid: | 
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6629 | LOG(FATAL) << "UNREACHABLE"; | 
|  | 6630 | UNREACHABLE(); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6631 | } | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6632 |  | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6633 | if (generate_null_check || cls->MustGenerateClinitCheck()) { | 
|  | 6634 | DCHECK(cls->CanCallRuntime()); | 
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6635 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(cls, cls); | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6636 | codegen_->AddSlowPath(slow_path); | 
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6637 |  | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6638 | if (generate_null_check) { | 
|  | 6639 | __ testl(out, out); | 
|  | 6640 | __ j(kEqual, slow_path->GetEntryLabel()); | 
|  | 6641 | } | 
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6642 |  | 
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6643 | if (cls->MustGenerateClinitCheck()) { | 
|  | 6644 | GenerateClassInitializationCheck(slow_path, out); | 
|  | 6645 | } else { | 
|  | 6646 | __ Bind(slow_path->GetExitLabel()); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6647 | } | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6648 | } | 
|  | 6649 | } | 
|  | 6650 |  | 
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6651 | void LocationsBuilderX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { | 
|  | 6652 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 6653 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); | 
|  | 6654 | CodeGenerator::CreateLoadMethodHandleRuntimeCallLocationSummary(load, location, location); | 
|  | 6655 | } | 
|  | 6656 |  | 
|  | 6657 | void InstructionCodeGeneratorX86::VisitLoadMethodHandle(HLoadMethodHandle* load) { | 
|  | 6658 | codegen_->GenerateLoadMethodHandleRuntimeCall(load); | 
|  | 6659 | } | 
|  | 6660 |  | 
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6661 | void LocationsBuilderX86::VisitLoadMethodType(HLoadMethodType* load) { | 
|  | 6662 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 6663 | Location location = Location::RegisterLocation(calling_convention.GetRegisterAt(0)); | 
|  | 6664 | CodeGenerator::CreateLoadMethodTypeRuntimeCallLocationSummary(load, location, location); | 
|  | 6665 | } | 
|  | 6666 |  | 
|  | 6667 | void InstructionCodeGeneratorX86::VisitLoadMethodType(HLoadMethodType* load) { | 
|  | 6668 | codegen_->GenerateLoadMethodTypeRuntimeCall(load); | 
|  | 6669 | } | 
|  | 6670 |  | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6671 | void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) { | 
|  | 6672 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6673 | new (GetGraph()->GetAllocator()) LocationSummary(check, LocationSummary::kCallOnSlowPath); | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6674 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 6675 | if (check->HasUses()) { | 
|  | 6676 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 6677 | } | 
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6678 | // Rely on the type initialization to save everything we need. | 
|  | 6679 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6680 | } | 
|  | 6681 |  | 
|  | 6682 | void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) { | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6683 | // We assume the class to not be null. | 
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6684 | SlowPathCode* slow_path = | 
|  | 6685 | new (codegen_->GetScopedAllocator()) LoadClassSlowPathX86(check->GetLoadClass(), check); | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6686 | codegen_->AddSlowPath(slow_path); | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 6687 | GenerateClassInitializationCheck(slow_path, | 
|  | 6688 | check->GetLocations()->InAt(0).AsRegister<Register>()); | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6689 | } | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6690 |  | 
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6691 | void InstructionCodeGeneratorX86::GenerateClassInitializationCheck( | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6692 | SlowPathCode* slow_path, Register class_reg) { | 
| Vladimir Marko | dc682aa | 2018-01-04 18:42:57 +0000 | [diff] [blame] | 6693 | constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); | 
|  | 6694 | const size_t status_byte_offset = | 
|  | 6695 | mirror::Class::StatusOffset().SizeValue() + (status_lsb_position / kBitsPerByte); | 
|  | 6696 | constexpr uint32_t shifted_initialized_value = | 
|  | 6697 | enum_cast<uint32_t>(ClassStatus::kInitialized) << (status_lsb_position % kBitsPerByte); | 
|  | 6698 |  | 
|  | 6699 | __ cmpb(Address(class_reg,  status_byte_offset), Immediate(shifted_initialized_value)); | 
| Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 6700 | __ j(kBelow, slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6701 | __ Bind(slow_path->GetExitLabel()); | 
|  | 6702 | // No need for memory fence, thanks to the X86 memory model. | 
|  | 6703 | } | 
|  | 6704 |  | 
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6705 | void InstructionCodeGeneratorX86::GenerateBitstringTypeCheckCompare(HTypeCheckInstruction* check, | 
|  | 6706 | Register temp) { | 
|  | 6707 | uint32_t path_to_root = check->GetBitstringPathToRoot(); | 
|  | 6708 | uint32_t mask = check->GetBitstringMask(); | 
|  | 6709 | DCHECK(IsPowerOfTwo(mask + 1)); | 
|  | 6710 | size_t mask_bits = WhichPowerOf2(mask + 1); | 
|  | 6711 |  | 
|  | 6712 | if (mask_bits == 16u) { | 
|  | 6713 | // Compare the bitstring in memory. | 
|  | 6714 | __ cmpw(Address(temp, mirror::Class::StatusOffset()), Immediate(path_to_root)); | 
|  | 6715 | } else { | 
|  | 6716 | // /* uint32_t */ temp = temp->status_ | 
|  | 6717 | __ movl(temp, Address(temp, mirror::Class::StatusOffset())); | 
|  | 6718 | // Compare the bitstring bits using SUB. | 
|  | 6719 | __ subl(temp, Immediate(path_to_root)); | 
|  | 6720 | // Shift out bits that do not contribute to the comparison. | 
|  | 6721 | __ shll(temp, Immediate(32u - mask_bits)); | 
|  | 6722 | } | 
|  | 6723 | } | 
|  | 6724 |  | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6725 | HLoadString::LoadKind CodeGeneratorX86::GetSupportedLoadStringKind( | 
|  | 6726 | HLoadString::LoadKind desired_string_load_kind) { | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6727 | switch (desired_string_load_kind) { | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6728 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6729 | case HLoadString::LoadKind::kBootImageRelRo: | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6730 | case HLoadString::LoadKind::kBssEntry: | 
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6731 | DCHECK(!Runtime::Current()->UseJitCompilation()); | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6732 | break; | 
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6733 | case HLoadString::LoadKind::kJitBootImageAddress: | 
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6734 | case HLoadString::LoadKind::kJitTableAddress: | 
|  | 6735 | DCHECK(Runtime::Current()->UseJitCompilation()); | 
|  | 6736 | break; | 
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6737 | case HLoadString::LoadKind::kRuntimeCall: | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6738 | break; | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6739 | } | 
|  | 6740 | return desired_string_load_kind; | 
|  | 6741 | } | 
|  | 6742 |  | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6743 | void LocationsBuilderX86::VisitLoadString(HLoadString* load) { | 
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6744 | LocationSummary::CallKind call_kind = CodeGenerator::GetLoadStringCallKind(load); | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6745 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(load, call_kind); | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6746 | HLoadString::LoadKind load_kind = load->GetLoadKind(); | 
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6747 | if (load_kind == HLoadString::LoadKind::kBootImageLinkTimePcRelative || | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6748 | load_kind == HLoadString::LoadKind::kBootImageRelRo || | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6749 | load_kind == HLoadString::LoadKind::kBssEntry) { | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6750 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 6751 | } | 
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6752 | if (load_kind == HLoadString::LoadKind::kRuntimeCall) { | 
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6753 | locations->SetOut(Location::RegisterLocation(EAX)); | 
|  | 6754 | } else { | 
|  | 6755 | locations->SetOut(Location::RequiresRegister()); | 
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6756 | if (load_kind == HLoadString::LoadKind::kBssEntry) { | 
|  | 6757 | if (!kUseReadBarrier || kUseBakerReadBarrier) { | 
| Vladimir Marko | ea4c126 | 2017-02-06 19:59:33 +0000 | [diff] [blame] | 6758 | // Rely on the pResolveString to save everything. | 
| Vladimir Marko | 3232dbb | 2018-07-25 15:42:46 +0100 | [diff] [blame] | 6759 | locations->SetCustomSlowPathCallerSaves(OneRegInReferenceOutSaveEverythingCallerSaves()); | 
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6760 | } else { | 
|  | 6761 | // For non-Baker read barrier we have a temp-clobbering call. | 
|  | 6762 | } | 
|  | 6763 | } | 
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6764 | } | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6765 | } | 
|  | 6766 |  | 
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6767 | Label* CodeGeneratorX86::NewJitRootStringPatch(const DexFile& dex_file, | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6768 | dex::StringIndex string_index, | 
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6769 | Handle<mirror::String> handle) { | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6770 | ReserveJitStringRoot(StringReference(&dex_file, string_index), handle); | 
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6771 | // Add a patch entry and return the label. | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6772 | jit_string_patches_.emplace_back(&dex_file, string_index.index_); | 
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6773 | PatchInfo<Label>* info = &jit_string_patches_.back(); | 
|  | 6774 | return &info->label; | 
|  | 6775 | } | 
|  | 6776 |  | 
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6777 | // NO_THREAD_SAFETY_ANALYSIS as we manipulate handles whose internal object we know does not | 
|  | 6778 | // move. | 
|  | 6779 | void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) NO_THREAD_SAFETY_ANALYSIS { | 
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6780 | LocationSummary* locations = load->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6781 | Location out_loc = locations->Out(); | 
|  | 6782 | Register out = out_loc.AsRegister<Register>(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6783 |  | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6784 | switch (load->GetLoadKind()) { | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6785 | case HLoadString::LoadKind::kBootImageLinkTimePcRelative: { | 
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6786 | DCHECK(codegen_->GetCompilerOptions().IsBootImage()); | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6787 | Register method_address = locations->InAt(0).AsRegister<Register>(); | 
|  | 6788 | __ leal(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 6789 | codegen_->RecordBootImageStringPatch(load); | 
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6790 | return; | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6791 | } | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6792 | case HLoadString::LoadKind::kBootImageRelRo: { | 
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6793 | DCHECK(!codegen_->GetCompilerOptions().IsBootImage()); | 
|  | 6794 | Register method_address = locations->InAt(0).AsRegister<Register>(); | 
|  | 6795 | __ movl(out, Address(method_address, CodeGeneratorX86::kDummy32BitOffset)); | 
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6796 | codegen_->RecordBootImageRelRoPatch(load->InputAt(0)->AsX86ComputeBaseMethodAddress(), | 
|  | 6797 | codegen_->GetBootImageOffset(load)); | 
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6798 | return; | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6799 | } | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6800 | case HLoadString::LoadKind::kBssEntry: { | 
|  | 6801 | Register method_address = locations->InAt(0).AsRegister<Register>(); | 
|  | 6802 | Address address = Address(method_address, CodeGeneratorX86::kDummy32BitOffset); | 
|  | 6803 | Label* fixup_label = codegen_->NewStringBssEntryPatch(load); | 
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6804 | // /* GcRoot<mirror::String> */ out = *address  /* PC-relative */ | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 6805 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 6806 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) LoadStringSlowPathX86(load); | 
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6807 | codegen_->AddSlowPath(slow_path); | 
|  | 6808 | __ testl(out, out); | 
|  | 6809 | __ j(kEqual, slow_path->GetEntryLabel()); | 
|  | 6810 | __ Bind(slow_path->GetExitLabel()); | 
|  | 6811 | return; | 
|  | 6812 | } | 
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6813 | case HLoadString::LoadKind::kJitBootImageAddress: { | 
|  | 6814 | uint32_t address = reinterpret_cast32<uint32_t>(load->GetString().Get()); | 
|  | 6815 | DCHECK_NE(address, 0u); | 
|  | 6816 | __ movl(out, Immediate(address)); | 
|  | 6817 | return; | 
|  | 6818 | } | 
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6819 | case HLoadString::LoadKind::kJitTableAddress: { | 
|  | 6820 | Address address = Address::Absolute(CodeGeneratorX86::kDummy32BitOffset); | 
|  | 6821 | Label* fixup_label = codegen_->NewJitRootStringPatch( | 
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6822 | load->GetDexFile(), load->GetStringIndex(), load->GetString()); | 
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6823 | // /* GcRoot<mirror::String> */ out = *address | 
|  | 6824 | GenerateGcRootFieldLoad(load, out_loc, address, fixup_label, kCompilerReadBarrierOption); | 
|  | 6825 | return; | 
|  | 6826 | } | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6827 | default: | 
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6828 | break; | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6829 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6830 |  | 
| Christina Wadsworth | bf44e0e | 2016-08-18 10:37:42 -0700 | [diff] [blame] | 6831 | // TODO: Re-add the compiler code to do string dex cache lookup again. | 
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6832 | InvokeRuntimeCallingConvention calling_convention; | 
| Vladimir Marko | 94ce9c2 | 2016-09-30 14:50:51 +0100 | [diff] [blame] | 6833 | DCHECK_EQ(calling_convention.GetRegisterAt(0), out); | 
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6834 | __ movl(calling_convention.GetRegisterAt(0), Immediate(load->GetStringIndex().index_)); | 
| Christina Wadsworth | 175d09b | 2016-08-31 16:26:01 -0700 | [diff] [blame] | 6835 | codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc()); | 
|  | 6836 | CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>(); | 
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6837 | } | 
|  | 6838 |  | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6839 | static Address GetExceptionTlsAddress() { | 
| Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 6840 | return Address::Absolute(Thread::ExceptionOffset<kX86PointerSize>().Int32Value()); | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6841 | } | 
|  | 6842 |  | 
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6843 | void LocationsBuilderX86::VisitLoadException(HLoadException* load) { | 
|  | 6844 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6845 | new (GetGraph()->GetAllocator()) LocationSummary(load, LocationSummary::kNoCall); | 
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6846 | locations->SetOut(Location::RequiresRegister()); | 
|  | 6847 | } | 
|  | 6848 |  | 
|  | 6849 | void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) { | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6850 | __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), GetExceptionTlsAddress()); | 
|  | 6851 | } | 
|  | 6852 |  | 
|  | 6853 | void LocationsBuilderX86::VisitClearException(HClearException* clear) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6854 | new (GetGraph()->GetAllocator()) LocationSummary(clear, LocationSummary::kNoCall); | 
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6855 | } | 
|  | 6856 |  | 
|  | 6857 | void InstructionCodeGeneratorX86::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) { | 
|  | 6858 | __ fs()->movl(GetExceptionTlsAddress(), Immediate(0)); | 
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6859 | } | 
|  | 6860 |  | 
|  | 6861 | void LocationsBuilderX86::VisitThrow(HThrow* instruction) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6862 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( | 
|  | 6863 | instruction, LocationSummary::kCallOnMainOnly); | 
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6864 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 6865 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 6866 | } | 
|  | 6867 |  | 
|  | 6868 | void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) { | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 6869 | codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc()); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 6870 | CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>(); | 
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6871 | } | 
|  | 6872 |  | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6873 | // Temp is used for read barrier. | 
|  | 6874 | static size_t NumberOfInstanceOfTemps(TypeCheckKind type_check_kind) { | 
|  | 6875 | if (kEmitCompilerReadBarrier && | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 6876 | !kUseBakerReadBarrier && | 
|  | 6877 | (type_check_kind == TypeCheckKind::kAbstractClassCheck || | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6878 | type_check_kind == TypeCheckKind::kClassHierarchyCheck || | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6879 | type_check_kind == TypeCheckKind::kArrayObjectCheck)) { | 
|  | 6880 | return 1; | 
|  | 6881 | } | 
|  | 6882 | return 0; | 
|  | 6883 | } | 
|  | 6884 |  | 
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 6885 | // Interface case has 2 temps, one for holding the number of interfaces, one for the current | 
|  | 6886 | // interface pointer, the current interface is compared in memory. | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6887 | // The other checks have one temp for loading the object's class. | 
|  | 6888 | static size_t NumberOfCheckCastTemps(TypeCheckKind type_check_kind) { | 
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 6889 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6890 | return 2; | 
|  | 6891 | } | 
|  | 6892 | return 1 + NumberOfInstanceOfTemps(type_check_kind); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6893 | } | 
|  | 6894 |  | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6895 | void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6896 | LocationSummary::CallKind call_kind = LocationSummary::kNoCall; | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6897 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); | 
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6898 | bool baker_read_barrier_slow_path = false; | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6899 | switch (type_check_kind) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6900 | case TypeCheckKind::kExactCheck: | 
|  | 6901 | case TypeCheckKind::kAbstractClassCheck: | 
|  | 6902 | case TypeCheckKind::kClassHierarchyCheck: | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6903 | case TypeCheckKind::kArrayObjectCheck: { | 
|  | 6904 | bool needs_read_barrier = CodeGenerator::InstanceOfNeedsReadBarrier(instruction); | 
|  | 6905 | call_kind = needs_read_barrier ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall; | 
|  | 6906 | baker_read_barrier_slow_path = kUseBakerReadBarrier && needs_read_barrier; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6907 | break; | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6908 | } | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6909 | case TypeCheckKind::kArrayCheck: | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6910 | case TypeCheckKind::kUnresolvedCheck: | 
|  | 6911 | case TypeCheckKind::kInterfaceCheck: | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6912 | call_kind = LocationSummary::kCallOnSlowPath; | 
|  | 6913 | break; | 
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6914 | case TypeCheckKind::kBitstringCheck: | 
|  | 6915 | break; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6916 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6917 |  | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 6918 | LocationSummary* locations = | 
|  | 6919 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); | 
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6920 | if (baker_read_barrier_slow_path) { | 
| Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 6921 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty());  // No caller-save registers. | 
| Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 6922 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6923 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6924 | if (type_check_kind == TypeCheckKind::kBitstringCheck) { | 
|  | 6925 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); | 
|  | 6926 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); | 
|  | 6927 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); | 
|  | 6928 | } else { | 
|  | 6929 | locations->SetInAt(1, Location::Any()); | 
|  | 6930 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6931 | // Note that TypeCheckSlowPathX86 uses this "out" register too. | 
|  | 6932 | locations->SetOut(Location::RequiresRegister()); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6933 | // When read barriers are enabled, we need a temporary register for some cases. | 
|  | 6934 | locations->AddRegisterTemps(NumberOfInstanceOfTemps(type_check_kind)); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6935 | } | 
|  | 6936 |  | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6937 | void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6938 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6939 | LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6940 | Location obj_loc = locations->InAt(0); | 
|  | 6941 | Register obj = obj_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6942 | Location cls = locations->InAt(1); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6943 | Location out_loc = locations->Out(); | 
|  | 6944 | Register out = out_loc.AsRegister<Register>(); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 6945 | const size_t num_temps = NumberOfInstanceOfTemps(type_check_kind); | 
|  | 6946 | DCHECK_LE(num_temps, 1u); | 
|  | 6947 | Location maybe_temp_loc = (num_temps >= 1) ? locations->GetTemp(0) : Location::NoLocation(); | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6948 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6949 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); | 
|  | 6950 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); | 
|  | 6951 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 6952 | SlowPathCode* slow_path = nullptr; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6953 | NearLabel done, zero; | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6954 |  | 
|  | 6955 | // Return 0 if `obj` is null. | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 6956 | // Avoid null check if we know obj is not null. | 
|  | 6957 | if (instruction->MustDoNullCheck()) { | 
|  | 6958 | __ testl(obj, obj); | 
|  | 6959 | __ j(kEqual, &zero); | 
|  | 6960 | } | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6961 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 6962 | switch (type_check_kind) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6963 | case TypeCheckKind::kExactCheck: { | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6964 | ReadBarrierOption read_barrier_option = | 
|  | 6965 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); | 
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6966 | // /* HeapReference<Class> */ out = obj->klass_ | 
|  | 6967 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 6968 | out_loc, | 
|  | 6969 | obj_loc, | 
|  | 6970 | class_offset, | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6971 | read_barrier_option); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6972 | if (cls.IsRegister()) { | 
|  | 6973 | __ cmpl(out, cls.AsRegister<Register>()); | 
|  | 6974 | } else { | 
|  | 6975 | DCHECK(cls.IsStackSlot()) << cls; | 
|  | 6976 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
|  | 6977 | } | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 6978 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6979 | // Classes must be equal for the instanceof to succeed. | 
|  | 6980 | __ j(kNotEqual, &zero); | 
|  | 6981 | __ movl(out, Immediate(1)); | 
|  | 6982 | __ jmp(&done); | 
|  | 6983 | break; | 
|  | 6984 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6985 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6986 | case TypeCheckKind::kAbstractClassCheck: { | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6987 | ReadBarrierOption read_barrier_option = | 
|  | 6988 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); | 
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 6989 | // /* HeapReference<Class> */ out = obj->klass_ | 
|  | 6990 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 6991 | out_loc, | 
|  | 6992 | obj_loc, | 
|  | 6993 | class_offset, | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 6994 | read_barrier_option); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6995 | // If the class is abstract, we eagerly fetch the super class of the | 
|  | 6996 | // object to avoid doing a comparison we know will fail. | 
|  | 6997 | NearLabel loop; | 
|  | 6998 | __ Bind(&loop); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 6999 | // /* HeapReference<Class> */ out = out->super_class_ | 
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7000 | GenerateReferenceLoadOneRegister(instruction, | 
|  | 7001 | out_loc, | 
|  | 7002 | super_offset, | 
|  | 7003 | maybe_temp_loc, | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7004 | read_barrier_option); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7005 | __ testl(out, out); | 
|  | 7006 | // If `out` is null, we use it for the result, and jump to `done`. | 
|  | 7007 | __ j(kEqual, &done); | 
|  | 7008 | if (cls.IsRegister()) { | 
|  | 7009 | __ cmpl(out, cls.AsRegister<Register>()); | 
|  | 7010 | } else { | 
|  | 7011 | DCHECK(cls.IsStackSlot()) << cls; | 
|  | 7012 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
|  | 7013 | } | 
|  | 7014 | __ j(kNotEqual, &loop); | 
|  | 7015 | __ movl(out, Immediate(1)); | 
|  | 7016 | if (zero.IsLinked()) { | 
|  | 7017 | __ jmp(&done); | 
|  | 7018 | } | 
|  | 7019 | break; | 
|  | 7020 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7021 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7022 | case TypeCheckKind::kClassHierarchyCheck: { | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7023 | ReadBarrierOption read_barrier_option = | 
|  | 7024 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); | 
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7025 | // /* HeapReference<Class> */ out = obj->klass_ | 
|  | 7026 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7027 | out_loc, | 
|  | 7028 | obj_loc, | 
|  | 7029 | class_offset, | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7030 | read_barrier_option); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7031 | // Walk over the class hierarchy to find a match. | 
|  | 7032 | NearLabel loop, success; | 
|  | 7033 | __ Bind(&loop); | 
|  | 7034 | if (cls.IsRegister()) { | 
|  | 7035 | __ cmpl(out, cls.AsRegister<Register>()); | 
|  | 7036 | } else { | 
|  | 7037 | DCHECK(cls.IsStackSlot()) << cls; | 
|  | 7038 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
|  | 7039 | } | 
|  | 7040 | __ j(kEqual, &success); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7041 | // /* HeapReference<Class> */ out = out->super_class_ | 
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7042 | GenerateReferenceLoadOneRegister(instruction, | 
|  | 7043 | out_loc, | 
|  | 7044 | super_offset, | 
|  | 7045 | maybe_temp_loc, | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7046 | read_barrier_option); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7047 | __ testl(out, out); | 
|  | 7048 | __ j(kNotEqual, &loop); | 
|  | 7049 | // If `out` is null, we use it for the result, and jump to `done`. | 
|  | 7050 | __ jmp(&done); | 
|  | 7051 | __ Bind(&success); | 
|  | 7052 | __ movl(out, Immediate(1)); | 
|  | 7053 | if (zero.IsLinked()) { | 
|  | 7054 | __ jmp(&done); | 
|  | 7055 | } | 
|  | 7056 | break; | 
|  | 7057 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7058 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7059 | case TypeCheckKind::kArrayObjectCheck: { | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7060 | ReadBarrierOption read_barrier_option = | 
|  | 7061 | CodeGenerator::ReadBarrierOptionForInstanceOf(instruction); | 
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7062 | // /* HeapReference<Class> */ out = obj->klass_ | 
|  | 7063 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7064 | out_loc, | 
|  | 7065 | obj_loc, | 
|  | 7066 | class_offset, | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7067 | read_barrier_option); | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7068 | // Do an exact check. | 
|  | 7069 | NearLabel exact_check; | 
|  | 7070 | if (cls.IsRegister()) { | 
|  | 7071 | __ cmpl(out, cls.AsRegister<Register>()); | 
|  | 7072 | } else { | 
|  | 7073 | DCHECK(cls.IsStackSlot()) << cls; | 
|  | 7074 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
|  | 7075 | } | 
|  | 7076 | __ j(kEqual, &exact_check); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7077 | // Otherwise, we need to check that the object's class is a non-primitive array. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7078 | // /* HeapReference<Class> */ out = out->component_type_ | 
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7079 | GenerateReferenceLoadOneRegister(instruction, | 
|  | 7080 | out_loc, | 
|  | 7081 | component_offset, | 
|  | 7082 | maybe_temp_loc, | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7083 | read_barrier_option); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7084 | __ testl(out, out); | 
|  | 7085 | // If `out` is null, we use it for the result, and jump to `done`. | 
|  | 7086 | __ j(kEqual, &done); | 
|  | 7087 | __ cmpw(Address(out, primitive_offset), Immediate(Primitive::kPrimNot)); | 
|  | 7088 | __ j(kNotEqual, &zero); | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7089 | __ Bind(&exact_check); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7090 | __ movl(out, Immediate(1)); | 
|  | 7091 | __ jmp(&done); | 
|  | 7092 | break; | 
|  | 7093 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7094 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7095 | case TypeCheckKind::kArrayCheck: { | 
| Mathieu Chartier | 9fd8c60 | 2016-11-14 14:38:53 -0800 | [diff] [blame] | 7096 | // No read barrier since the slow path will retry upon failure. | 
|  | 7097 | // /* HeapReference<Class> */ out = obj->klass_ | 
|  | 7098 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7099 | out_loc, | 
|  | 7100 | obj_loc, | 
|  | 7101 | class_offset, | 
|  | 7102 | kWithoutReadBarrier); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7103 | if (cls.IsRegister()) { | 
|  | 7104 | __ cmpl(out, cls.AsRegister<Register>()); | 
|  | 7105 | } else { | 
|  | 7106 | DCHECK(cls.IsStackSlot()) << cls; | 
|  | 7107 | __ cmpl(out, Address(ESP, cls.GetStackIndex())); | 
|  | 7108 | } | 
|  | 7109 | DCHECK(locations->OnlyCallsOnSlowPath()); | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7110 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7111 | instruction, /* is_fatal= */ false); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7112 | codegen_->AddSlowPath(slow_path); | 
|  | 7113 | __ j(kNotEqual, slow_path->GetEntryLabel()); | 
|  | 7114 | __ movl(out, Immediate(1)); | 
|  | 7115 | if (zero.IsLinked()) { | 
|  | 7116 | __ jmp(&done); | 
|  | 7117 | } | 
|  | 7118 | break; | 
|  | 7119 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7120 |  | 
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7121 | case TypeCheckKind::kUnresolvedCheck: | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7122 | case TypeCheckKind::kInterfaceCheck: { | 
|  | 7123 | // Note that we indeed only call on slow path, but we always go | 
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7124 | // into the slow path for the unresolved and interface check | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7125 | // cases. | 
|  | 7126 | // | 
|  | 7127 | // We cannot directly call the InstanceofNonTrivial runtime | 
|  | 7128 | // entry point without resorting to a type checking slow path | 
|  | 7129 | // here (i.e. by calling InvokeRuntime directly), as it would | 
|  | 7130 | // require to assign fixed registers for the inputs of this | 
|  | 7131 | // HInstanceOf instruction (following the runtime calling | 
|  | 7132 | // convention), which might be cluttered by the potential first | 
|  | 7133 | // read barrier emission at the beginning of this method. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7134 | // | 
|  | 7135 | // TODO: Introduce a new runtime entry point taking the object | 
|  | 7136 | // to test (instead of its class) as argument, and let it deal | 
|  | 7137 | // with the read barrier issues. This will let us refactor this | 
|  | 7138 | // case of the `switch` code as it was previously (with a direct | 
|  | 7139 | // call to the runtime not using a type checking slow path). | 
|  | 7140 | // This should also be beneficial for the other cases above. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7141 | DCHECK(locations->OnlyCallsOnSlowPath()); | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7142 | slow_path = new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7143 | instruction, /* is_fatal= */ false); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7144 | codegen_->AddSlowPath(slow_path); | 
|  | 7145 | __ jmp(slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7146 | if (zero.IsLinked()) { | 
|  | 7147 | __ jmp(&done); | 
|  | 7148 | } | 
|  | 7149 | break; | 
|  | 7150 | } | 
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7151 |  | 
|  | 7152 | case TypeCheckKind::kBitstringCheck: { | 
|  | 7153 | // /* HeapReference<Class> */ temp = obj->klass_ | 
|  | 7154 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7155 | out_loc, | 
|  | 7156 | obj_loc, | 
|  | 7157 | class_offset, | 
|  | 7158 | kWithoutReadBarrier); | 
|  | 7159 |  | 
|  | 7160 | GenerateBitstringTypeCheckCompare(instruction, out); | 
|  | 7161 | __ j(kNotEqual, &zero); | 
|  | 7162 | __ movl(out, Immediate(1)); | 
|  | 7163 | __ jmp(&done); | 
|  | 7164 | break; | 
|  | 7165 | } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7166 | } | 
|  | 7167 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7168 | if (zero.IsLinked()) { | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7169 | __ Bind(&zero); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7170 | __ xorl(out, out); | 
|  | 7171 | } | 
|  | 7172 |  | 
|  | 7173 | if (done.IsLinked()) { | 
|  | 7174 | __ Bind(&done); | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7175 | } | 
|  | 7176 |  | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7177 | if (slow_path != nullptr) { | 
|  | 7178 | __ Bind(slow_path->GetExitLabel()); | 
|  | 7179 | } | 
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7180 | } | 
|  | 7181 |  | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7182 | void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7183 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7184 | LocationSummary::CallKind call_kind = CodeGenerator::GetCheckCastCallKind(instruction); | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7185 | LocationSummary* locations = | 
|  | 7186 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, call_kind); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7187 | locations->SetInAt(0, Location::RequiresRegister()); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7188 | if (type_check_kind == TypeCheckKind::kInterfaceCheck) { | 
|  | 7189 | // Require a register for the interface check since there is a loop that compares the class to | 
|  | 7190 | // a memory address. | 
|  | 7191 | locations->SetInAt(1, Location::RequiresRegister()); | 
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7192 | } else if (type_check_kind == TypeCheckKind::kBitstringCheck) { | 
|  | 7193 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); | 
|  | 7194 | locations->SetInAt(2, Location::ConstantLocation(instruction->InputAt(2)->AsConstant())); | 
|  | 7195 | locations->SetInAt(3, Location::ConstantLocation(instruction->InputAt(3)->AsConstant())); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7196 | } else { | 
|  | 7197 | locations->SetInAt(1, Location::Any()); | 
|  | 7198 | } | 
| Vladimir Marko | 9f8d312 | 2018-04-06 13:47:59 +0100 | [diff] [blame] | 7199 | // Add temps for read barriers and other uses. One is used by TypeCheckSlowPathX86. | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7200 | locations->AddRegisterTemps(NumberOfCheckCastTemps(type_check_kind)); | 
|  | 7201 | } | 
|  | 7202 |  | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7203 | void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7204 | TypeCheckKind type_check_kind = instruction->GetTypeCheckKind(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7205 | LocationSummary* locations = instruction->GetLocations(); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7206 | Location obj_loc = locations->InAt(0); | 
|  | 7207 | Register obj = obj_loc.AsRegister<Register>(); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7208 | Location cls = locations->InAt(1); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7209 | Location temp_loc = locations->GetTemp(0); | 
|  | 7210 | Register temp = temp_loc.AsRegister<Register>(); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7211 | const size_t num_temps = NumberOfCheckCastTemps(type_check_kind); | 
|  | 7212 | DCHECK_GE(num_temps, 1u); | 
|  | 7213 | DCHECK_LE(num_temps, 2u); | 
|  | 7214 | Location maybe_temp2_loc = (num_temps >= 2) ? locations->GetTemp(1) : Location::NoLocation(); | 
|  | 7215 | const uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); | 
|  | 7216 | const uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); | 
|  | 7217 | const uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); | 
|  | 7218 | const uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); | 
|  | 7219 | const uint32_t iftable_offset = mirror::Class::IfTableOffset().Uint32Value(); | 
|  | 7220 | const uint32_t array_length_offset = mirror::Array::LengthOffset().Uint32Value(); | 
|  | 7221 | const uint32_t object_array_data_offset = | 
|  | 7222 | mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7223 |  | 
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7224 | bool is_type_check_slow_path_fatal = CodeGenerator::IsTypeCheckSlowPathFatal(instruction); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7225 | SlowPathCode* type_check_slow_path = | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7226 | new (codegen_->GetScopedAllocator()) TypeCheckSlowPathX86( | 
|  | 7227 | instruction, is_type_check_slow_path_fatal); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7228 | codegen_->AddSlowPath(type_check_slow_path); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7229 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7230 | NearLabel done; | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7231 | // Avoid null check if we know obj is not null. | 
|  | 7232 | if (instruction->MustDoNullCheck()) { | 
|  | 7233 | __ testl(obj, obj); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7234 | __ j(kEqual, &done); | 
| Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 7235 | } | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7236 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7237 | switch (type_check_kind) { | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7238 | case TypeCheckKind::kExactCheck: | 
|  | 7239 | case TypeCheckKind::kArrayCheck: { | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7240 | // /* HeapReference<Class> */ temp = obj->klass_ | 
|  | 7241 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7242 | temp_loc, | 
|  | 7243 | obj_loc, | 
|  | 7244 | class_offset, | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7245 | kWithoutReadBarrier); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7246 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7247 | if (cls.IsRegister()) { | 
|  | 7248 | __ cmpl(temp, cls.AsRegister<Register>()); | 
|  | 7249 | } else { | 
|  | 7250 | DCHECK(cls.IsStackSlot()) << cls; | 
|  | 7251 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); | 
|  | 7252 | } | 
|  | 7253 | // Jump to slow path for throwing the exception or doing a | 
|  | 7254 | // more involved array check. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7255 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7256 | break; | 
|  | 7257 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7258 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7259 | case TypeCheckKind::kAbstractClassCheck: { | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7260 | // /* HeapReference<Class> */ temp = obj->klass_ | 
|  | 7261 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7262 | temp_loc, | 
|  | 7263 | obj_loc, | 
|  | 7264 | class_offset, | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7265 | kWithoutReadBarrier); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7266 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7267 | // If the class is abstract, we eagerly fetch the super class of the | 
|  | 7268 | // object to avoid doing a comparison we know will fail. | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7269 | NearLabel loop; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7270 | __ Bind(&loop); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7271 | // /* HeapReference<Class> */ temp = temp->super_class_ | 
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7272 | GenerateReferenceLoadOneRegister(instruction, | 
|  | 7273 | temp_loc, | 
|  | 7274 | super_offset, | 
|  | 7275 | maybe_temp2_loc, | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7276 | kWithoutReadBarrier); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7277 |  | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7278 | // If the class reference currently in `temp` is null, jump to the slow path to throw the | 
|  | 7279 | // exception. | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7280 | __ testl(temp, temp); | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7281 | __ j(kZero, type_check_slow_path->GetEntryLabel()); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7282 |  | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7283 | // Otherwise, compare the classes | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7284 | if (cls.IsRegister()) { | 
|  | 7285 | __ cmpl(temp, cls.AsRegister<Register>()); | 
|  | 7286 | } else { | 
|  | 7287 | DCHECK(cls.IsStackSlot()) << cls; | 
|  | 7288 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); | 
|  | 7289 | } | 
|  | 7290 | __ j(kNotEqual, &loop); | 
|  | 7291 | break; | 
|  | 7292 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7293 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7294 | case TypeCheckKind::kClassHierarchyCheck: { | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7295 | // /* HeapReference<Class> */ temp = obj->klass_ | 
|  | 7296 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7297 | temp_loc, | 
|  | 7298 | obj_loc, | 
|  | 7299 | class_offset, | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7300 | kWithoutReadBarrier); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7301 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7302 | // Walk over the class hierarchy to find a match. | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7303 | NearLabel loop; | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7304 | __ Bind(&loop); | 
|  | 7305 | if (cls.IsRegister()) { | 
|  | 7306 | __ cmpl(temp, cls.AsRegister<Register>()); | 
|  | 7307 | } else { | 
|  | 7308 | DCHECK(cls.IsStackSlot()) << cls; | 
|  | 7309 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); | 
|  | 7310 | } | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7311 | __ j(kEqual, &done); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7312 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7313 | // /* HeapReference<Class> */ temp = temp->super_class_ | 
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7314 | GenerateReferenceLoadOneRegister(instruction, | 
|  | 7315 | temp_loc, | 
|  | 7316 | super_offset, | 
|  | 7317 | maybe_temp2_loc, | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7318 | kWithoutReadBarrier); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7319 |  | 
|  | 7320 | // If the class reference currently in `temp` is not null, jump | 
|  | 7321 | // back at the beginning of the loop. | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7322 | __ testl(temp, temp); | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7323 | __ j(kNotZero, &loop); | 
|  | 7324 | // Otherwise, jump to the slow path to throw the exception.; | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7325 | __ jmp(type_check_slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7326 | break; | 
|  | 7327 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7328 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7329 | case TypeCheckKind::kArrayObjectCheck: { | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7330 | // /* HeapReference<Class> */ temp = obj->klass_ | 
|  | 7331 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7332 | temp_loc, | 
|  | 7333 | obj_loc, | 
|  | 7334 | class_offset, | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7335 | kWithoutReadBarrier); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7336 |  | 
| Nicolas Geoffray | abfcf18 | 2015-09-21 18:41:21 +0100 | [diff] [blame] | 7337 | // Do an exact check. | 
|  | 7338 | if (cls.IsRegister()) { | 
|  | 7339 | __ cmpl(temp, cls.AsRegister<Register>()); | 
|  | 7340 | } else { | 
|  | 7341 | DCHECK(cls.IsStackSlot()) << cls; | 
|  | 7342 | __ cmpl(temp, Address(ESP, cls.GetStackIndex())); | 
|  | 7343 | } | 
|  | 7344 | __ j(kEqual, &done); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7345 |  | 
|  | 7346 | // Otherwise, we need to check that the object's class is a non-primitive array. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7347 | // /* HeapReference<Class> */ temp = temp->component_type_ | 
| Mathieu Chartier | aa474eb | 2016-11-09 15:18:27 -0800 | [diff] [blame] | 7348 | GenerateReferenceLoadOneRegister(instruction, | 
|  | 7349 | temp_loc, | 
|  | 7350 | component_offset, | 
|  | 7351 | maybe_temp2_loc, | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7352 | kWithoutReadBarrier); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7353 |  | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7354 | // If the component type is null (i.e. the object not an array),  jump to the slow path to | 
|  | 7355 | // throw the exception. Otherwise proceed with the check. | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7356 | __ testl(temp, temp); | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7357 | __ j(kZero, type_check_slow_path->GetEntryLabel()); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7358 |  | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7359 | __ cmpw(Address(temp, primitive_offset), Immediate(Primitive::kPrimNot)); | 
| Mathieu Chartier | b99f4d6 | 2016-11-07 16:17:26 -0800 | [diff] [blame] | 7360 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7361 | break; | 
|  | 7362 | } | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7363 |  | 
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7364 | case TypeCheckKind::kUnresolvedCheck: | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7365 | // We always go into the type check slow path for the unresolved check case. | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7366 | // We cannot directly call the CheckCast runtime entry point | 
|  | 7367 | // without resorting to a type checking slow path here (i.e. by | 
|  | 7368 | // calling InvokeRuntime directly), as it would require to | 
|  | 7369 | // assign fixed registers for the inputs of this HInstanceOf | 
|  | 7370 | // instruction (following the runtime calling convention), which | 
|  | 7371 | // might be cluttered by the potential first read barrier | 
|  | 7372 | // emission at the beginning of this method. | 
|  | 7373 | __ jmp(type_check_slow_path->GetEntryLabel()); | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7374 | break; | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7375 |  | 
|  | 7376 | case TypeCheckKind::kInterfaceCheck: { | 
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7377 | // Fast path for the interface check. Try to avoid read barriers to improve the fast path. | 
|  | 7378 | // We can not get false positives by doing this. | 
|  | 7379 | // /* HeapReference<Class> */ temp = obj->klass_ | 
|  | 7380 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7381 | temp_loc, | 
|  | 7382 | obj_loc, | 
|  | 7383 | class_offset, | 
|  | 7384 | kWithoutReadBarrier); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7385 |  | 
| Vladimir Marko | e619f6c | 2017-12-12 16:00:01 +0000 | [diff] [blame] | 7386 | // /* HeapReference<Class> */ temp = temp->iftable_ | 
|  | 7387 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7388 | temp_loc, | 
|  | 7389 | temp_loc, | 
|  | 7390 | iftable_offset, | 
|  | 7391 | kWithoutReadBarrier); | 
|  | 7392 | // Iftable is never null. | 
|  | 7393 | __ movl(maybe_temp2_loc.AsRegister<Register>(), Address(temp, array_length_offset)); | 
|  | 7394 | // Maybe poison the `cls` for direct comparison with memory. | 
|  | 7395 | __ MaybePoisonHeapReference(cls.AsRegister<Register>()); | 
|  | 7396 | // Loop through the iftable and check if any class matches. | 
|  | 7397 | NearLabel start_loop; | 
|  | 7398 | __ Bind(&start_loop); | 
|  | 7399 | // Need to subtract first to handle the empty array case. | 
|  | 7400 | __ subl(maybe_temp2_loc.AsRegister<Register>(), Immediate(2)); | 
|  | 7401 | __ j(kNegative, type_check_slow_path->GetEntryLabel()); | 
|  | 7402 | // Go to next interface if the classes do not match. | 
|  | 7403 | __ cmpl(cls.AsRegister<Register>(), | 
|  | 7404 | CodeGeneratorX86::ArrayAddress(temp, | 
|  | 7405 | maybe_temp2_loc, | 
|  | 7406 | TIMES_4, | 
|  | 7407 | object_array_data_offset)); | 
|  | 7408 | __ j(kNotEqual, &start_loop); | 
|  | 7409 | // If `cls` was poisoned above, unpoison it. | 
|  | 7410 | __ MaybeUnpoisonHeapReference(cls.AsRegister<Register>()); | 
| Mathieu Chartier | 5c44c1b | 2016-11-04 18:13:04 -0700 | [diff] [blame] | 7411 | break; | 
|  | 7412 | } | 
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7413 |  | 
|  | 7414 | case TypeCheckKind::kBitstringCheck: { | 
|  | 7415 | // /* HeapReference<Class> */ temp = obj->klass_ | 
|  | 7416 | GenerateReferenceLoadTwoRegisters(instruction, | 
|  | 7417 | temp_loc, | 
|  | 7418 | obj_loc, | 
|  | 7419 | class_offset, | 
|  | 7420 | kWithoutReadBarrier); | 
|  | 7421 |  | 
|  | 7422 | GenerateBitstringTypeCheckCompare(instruction, temp); | 
|  | 7423 | __ j(kNotEqual, type_check_slow_path->GetEntryLabel()); | 
|  | 7424 | break; | 
|  | 7425 | } | 
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7426 | } | 
|  | 7427 | __ Bind(&done); | 
|  | 7428 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7429 | __ Bind(type_check_slow_path->GetExitLabel()); | 
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7430 | } | 
|  | 7431 |  | 
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7432 | void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7433 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary( | 
|  | 7434 | instruction, LocationSummary::kCallOnMainOnly); | 
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7435 | InvokeRuntimeCallingConvention calling_convention; | 
|  | 7436 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); | 
|  | 7437 | } | 
|  | 7438 |  | 
|  | 7439 | void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) { | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7440 | codegen_->InvokeRuntime(instruction->IsEnter() ? kQuickLockObject | 
|  | 7441 | : kQuickUnlockObject, | 
| Alexandre Rames | 8158f28 | 2015-08-07 10:26:17 +0100 | [diff] [blame] | 7442 | instruction, | 
| Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 7443 | instruction->GetDexPc()); | 
| Roland Levillain | 888d067 | 2015-11-23 18:53:50 +0000 | [diff] [blame] | 7444 | if (instruction->IsEnter()) { | 
|  | 7445 | CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>(); | 
|  | 7446 | } else { | 
|  | 7447 | CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>(); | 
|  | 7448 | } | 
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7449 | } | 
|  | 7450 |  | 
| Shalini Salomi Bodapati | dd121f6 | 2018-10-26 15:03:53 +0530 | [diff] [blame] | 7451 | void LocationsBuilderX86::VisitX86AndNot(HX86AndNot* instruction) { | 
|  | 7452 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); | 
|  | 7453 | DCHECK(DataType::IsIntOrLongType(instruction->GetType())) << instruction->GetType(); | 
|  | 7454 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); | 
|  | 7455 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 7456 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 7457 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 7458 | } | 
|  | 7459 |  | 
|  | 7460 | void InstructionCodeGeneratorX86::VisitX86AndNot(HX86AndNot* instruction) { | 
|  | 7461 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 7462 | Location first = locations->InAt(0); | 
|  | 7463 | Location second = locations->InAt(1); | 
|  | 7464 | Location dest = locations->Out(); | 
|  | 7465 | if (instruction->GetResultType() == DataType::Type::kInt32) { | 
|  | 7466 | __ andn(dest.AsRegister<Register>(), | 
|  | 7467 | first.AsRegister<Register>(), | 
|  | 7468 | second.AsRegister<Register>()); | 
|  | 7469 | } else { | 
|  | 7470 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); | 
|  | 7471 | __ andn(dest.AsRegisterPairLow<Register>(), | 
|  | 7472 | first.AsRegisterPairLow<Register>(), | 
|  | 7473 | second.AsRegisterPairLow<Register>()); | 
|  | 7474 | __ andn(dest.AsRegisterPairHigh<Register>(), | 
|  | 7475 | first.AsRegisterPairHigh<Register>(), | 
|  | 7476 | second.AsRegisterPairHigh<Register>()); | 
|  | 7477 | } | 
|  | 7478 | } | 
|  | 7479 |  | 
|  | 7480 | void LocationsBuilderX86::VisitX86MaskOrResetLeastSetBit(HX86MaskOrResetLeastSetBit* instruction) { | 
|  | 7481 | DCHECK(codegen_->GetInstructionSetFeatures().HasAVX2()); | 
|  | 7482 | DCHECK(instruction->GetType() == DataType::Type::kInt32) << instruction->GetType(); | 
|  | 7483 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); | 
|  | 7484 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 7485 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); | 
|  | 7486 | } | 
|  | 7487 |  | 
|  | 7488 | void InstructionCodeGeneratorX86::VisitX86MaskOrResetLeastSetBit( | 
|  | 7489 | HX86MaskOrResetLeastSetBit* instruction) { | 
|  | 7490 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 7491 | Location src = locations->InAt(0); | 
|  | 7492 | Location dest = locations->Out(); | 
|  | 7493 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32); | 
|  | 7494 | switch (instruction->GetOpKind()) { | 
|  | 7495 | case HInstruction::kAnd: | 
|  | 7496 | __ blsr(dest.AsRegister<Register>(), src.AsRegister<Register>()); | 
|  | 7497 | break; | 
|  | 7498 | case HInstruction::kXor: | 
|  | 7499 | __ blsmsk(dest.AsRegister<Register>(), src.AsRegister<Register>()); | 
|  | 7500 | break; | 
|  | 7501 | default: | 
|  | 7502 | LOG(FATAL) << "Unreachable"; | 
|  | 7503 | } | 
|  | 7504 | } | 
|  | 7505 |  | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7506 | void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); } | 
|  | 7507 | void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); } | 
|  | 7508 | void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); } | 
|  | 7509 |  | 
|  | 7510 | void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) { | 
|  | 7511 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7512 | new (GetGraph()->GetAllocator()) LocationSummary(instruction, LocationSummary::kNoCall); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7513 | DCHECK(instruction->GetResultType() == DataType::Type::kInt32 | 
|  | 7514 | || instruction->GetResultType() == DataType::Type::kInt64); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7515 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 7516 | locations->SetInAt(1, Location::Any()); | 
|  | 7517 | locations->SetOut(Location::SameAsFirstInput()); | 
|  | 7518 | } | 
|  | 7519 |  | 
|  | 7520 | void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) { | 
|  | 7521 | HandleBitwiseOperation(instruction); | 
|  | 7522 | } | 
|  | 7523 |  | 
|  | 7524 | void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) { | 
|  | 7525 | HandleBitwiseOperation(instruction); | 
|  | 7526 | } | 
|  | 7527 |  | 
|  | 7528 | void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) { | 
|  | 7529 | HandleBitwiseOperation(instruction); | 
|  | 7530 | } | 
|  | 7531 |  | 
|  | 7532 | void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) { | 
|  | 7533 | LocationSummary* locations = instruction->GetLocations(); | 
|  | 7534 | Location first = locations->InAt(0); | 
|  | 7535 | Location second = locations->InAt(1); | 
|  | 7536 | DCHECK(first.Equals(locations->Out())); | 
|  | 7537 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7538 | if (instruction->GetResultType() == DataType::Type::kInt32) { | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7539 | if (second.IsRegister()) { | 
|  | 7540 | if (instruction->IsAnd()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7541 | __ andl(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7542 | } else if (instruction->IsOr()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7543 | __ orl(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7544 | } else { | 
|  | 7545 | DCHECK(instruction->IsXor()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7546 | __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>()); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7547 | } | 
|  | 7548 | } else if (second.IsConstant()) { | 
|  | 7549 | if (instruction->IsAnd()) { | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7550 | __ andl(first.AsRegister<Register>(), | 
|  | 7551 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7552 | } else if (instruction->IsOr()) { | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7553 | __ orl(first.AsRegister<Register>(), | 
|  | 7554 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7555 | } else { | 
|  | 7556 | DCHECK(instruction->IsXor()); | 
| Roland Levillain | 199f336 | 2014-11-27 17:15:16 +0000 | [diff] [blame] | 7557 | __ xorl(first.AsRegister<Register>(), | 
|  | 7558 | Immediate(second.GetConstant()->AsIntConstant()->GetValue())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7559 | } | 
|  | 7560 | } else { | 
|  | 7561 | if (instruction->IsAnd()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7562 | __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7563 | } else if (instruction->IsOr()) { | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7564 | __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7565 | } else { | 
|  | 7566 | DCHECK(instruction->IsXor()); | 
| Roland Levillain | 271ab9c | 2014-11-27 15:23:57 +0000 | [diff] [blame] | 7567 | __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex())); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7568 | } | 
|  | 7569 | } | 
|  | 7570 | } else { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7571 | DCHECK_EQ(instruction->GetResultType(), DataType::Type::kInt64); | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7572 | if (second.IsRegisterPair()) { | 
|  | 7573 | if (instruction->IsAnd()) { | 
|  | 7574 | __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
|  | 7575 | __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
|  | 7576 | } else if (instruction->IsOr()) { | 
|  | 7577 | __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
|  | 7578 | __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
|  | 7579 | } else { | 
|  | 7580 | DCHECK(instruction->IsXor()); | 
|  | 7581 | __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>()); | 
|  | 7582 | __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>()); | 
|  | 7583 | } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7584 | } else if (second.IsDoubleStackSlot()) { | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7585 | if (instruction->IsAnd()) { | 
|  | 7586 | __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
|  | 7587 | __ andl(first.AsRegisterPairHigh<Register>(), | 
|  | 7588 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
|  | 7589 | } else if (instruction->IsOr()) { | 
|  | 7590 | __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
|  | 7591 | __ orl(first.AsRegisterPairHigh<Register>(), | 
|  | 7592 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
|  | 7593 | } else { | 
|  | 7594 | DCHECK(instruction->IsXor()); | 
|  | 7595 | __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex())); | 
|  | 7596 | __ xorl(first.AsRegisterPairHigh<Register>(), | 
|  | 7597 | Address(ESP, second.GetHighStackIndex(kX86WordSize))); | 
|  | 7598 | } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7599 | } else { | 
|  | 7600 | DCHECK(second.IsConstant()) << second; | 
|  | 7601 | int64_t value = second.GetConstant()->AsLongConstant()->GetValue(); | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7602 | int32_t low_value = Low32Bits(value); | 
|  | 7603 | int32_t high_value = High32Bits(value); | 
|  | 7604 | Immediate low(low_value); | 
|  | 7605 | Immediate high(high_value); | 
|  | 7606 | Register first_low = first.AsRegisterPairLow<Register>(); | 
|  | 7607 | Register first_high = first.AsRegisterPairHigh<Register>(); | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7608 | if (instruction->IsAnd()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7609 | if (low_value == 0) { | 
|  | 7610 | __ xorl(first_low, first_low); | 
|  | 7611 | } else if (low_value != -1) { | 
|  | 7612 | __ andl(first_low, low); | 
|  | 7613 | } | 
|  | 7614 | if (high_value == 0) { | 
|  | 7615 | __ xorl(first_high, first_high); | 
|  | 7616 | } else if (high_value != -1) { | 
|  | 7617 | __ andl(first_high, high); | 
|  | 7618 | } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7619 | } else if (instruction->IsOr()) { | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7620 | if (low_value != 0) { | 
|  | 7621 | __ orl(first_low, low); | 
|  | 7622 | } | 
|  | 7623 | if (high_value != 0) { | 
|  | 7624 | __ orl(first_high, high); | 
|  | 7625 | } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7626 | } else { | 
|  | 7627 | DCHECK(instruction->IsXor()); | 
| Mark Mendell | 3f6c7f6 | 2015-03-13 13:47:53 -0400 | [diff] [blame] | 7628 | if (low_value != 0) { | 
|  | 7629 | __ xorl(first_low, low); | 
|  | 7630 | } | 
|  | 7631 | if (high_value != 0) { | 
|  | 7632 | __ xorl(first_high, high); | 
|  | 7633 | } | 
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7634 | } | 
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 7635 | } | 
|  | 7636 | } | 
|  | 7637 | } | 
|  | 7638 |  | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7639 | void InstructionCodeGeneratorX86::GenerateReferenceLoadOneRegister( | 
|  | 7640 | HInstruction* instruction, | 
|  | 7641 | Location out, | 
|  | 7642 | uint32_t offset, | 
|  | 7643 | Location maybe_temp, | 
|  | 7644 | ReadBarrierOption read_barrier_option) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7645 | Register out_reg = out.AsRegister<Register>(); | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7646 | if (read_barrier_option == kWithReadBarrier) { | 
|  | 7647 | CHECK(kEmitCompilerReadBarrier); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7648 | if (kUseBakerReadBarrier) { | 
|  | 7649 | // Load with fast path based Baker's read barrier. | 
|  | 7650 | // /* HeapReference<Object> */ out = *(out + offset) | 
|  | 7651 | codegen_->GenerateFieldLoadWithBakerReadBarrier( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7652 | instruction, out, out_reg, offset, /* needs_null_check= */ false); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7653 | } else { | 
|  | 7654 | // Load with slow path based read barrier. | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7655 | // Save the value of `out` into `maybe_temp` before overwriting it | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7656 | // in the following move operation, as we will need it for the | 
|  | 7657 | // read barrier below. | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7658 | DCHECK(maybe_temp.IsRegister()) << maybe_temp; | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7659 | __ movl(maybe_temp.AsRegister<Register>(), out_reg); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7660 | // /* HeapReference<Object> */ out = *(out + offset) | 
|  | 7661 | __ movl(out_reg, Address(out_reg, offset)); | 
| Roland Levillain | 95e7ffc | 2016-01-22 11:57:25 +0000 | [diff] [blame] | 7662 | codegen_->GenerateReadBarrierSlow(instruction, out, out, maybe_temp, offset); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7663 | } | 
|  | 7664 | } else { | 
|  | 7665 | // Plain load with no read barrier. | 
|  | 7666 | // /* HeapReference<Object> */ out = *(out + offset) | 
|  | 7667 | __ movl(out_reg, Address(out_reg, offset)); | 
|  | 7668 | __ MaybeUnpoisonHeapReference(out_reg); | 
|  | 7669 | } | 
|  | 7670 | } | 
|  | 7671 |  | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7672 | void InstructionCodeGeneratorX86::GenerateReferenceLoadTwoRegisters( | 
|  | 7673 | HInstruction* instruction, | 
|  | 7674 | Location out, | 
|  | 7675 | Location obj, | 
|  | 7676 | uint32_t offset, | 
|  | 7677 | ReadBarrierOption read_barrier_option) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7678 | Register out_reg = out.AsRegister<Register>(); | 
|  | 7679 | Register obj_reg = obj.AsRegister<Register>(); | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7680 | if (read_barrier_option == kWithReadBarrier) { | 
|  | 7681 | CHECK(kEmitCompilerReadBarrier); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7682 | if (kUseBakerReadBarrier) { | 
|  | 7683 | // Load with fast path based Baker's read barrier. | 
|  | 7684 | // /* HeapReference<Object> */ out = *(obj + offset) | 
|  | 7685 | codegen_->GenerateFieldLoadWithBakerReadBarrier( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7686 | instruction, out, obj_reg, offset, /* needs_null_check= */ false); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7687 | } else { | 
|  | 7688 | // Load with slow path based read barrier. | 
|  | 7689 | // /* HeapReference<Object> */ out = *(obj + offset) | 
|  | 7690 | __ movl(out_reg, Address(obj_reg, offset)); | 
|  | 7691 | codegen_->GenerateReadBarrierSlow(instruction, out, out, obj, offset); | 
|  | 7692 | } | 
|  | 7693 | } else { | 
|  | 7694 | // Plain load with no read barrier. | 
|  | 7695 | // /* HeapReference<Object> */ out = *(obj + offset) | 
|  | 7696 | __ movl(out_reg, Address(obj_reg, offset)); | 
|  | 7697 | __ MaybeUnpoisonHeapReference(out_reg); | 
|  | 7698 | } | 
|  | 7699 | } | 
|  | 7700 |  | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7701 | void InstructionCodeGeneratorX86::GenerateGcRootFieldLoad( | 
|  | 7702 | HInstruction* instruction, | 
|  | 7703 | Location root, | 
|  | 7704 | const Address& address, | 
|  | 7705 | Label* fixup_label, | 
|  | 7706 | ReadBarrierOption read_barrier_option) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7707 | Register root_reg = root.AsRegister<Register>(); | 
| Mathieu Chartier | 3af00dc | 2016-11-10 11:25:57 -0800 | [diff] [blame] | 7708 | if (read_barrier_option == kWithReadBarrier) { | 
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 7709 | DCHECK(kEmitCompilerReadBarrier); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7710 | if (kUseBakerReadBarrier) { | 
|  | 7711 | // Fast path implementation of art::ReadBarrier::BarrierForRoot when | 
|  | 7712 | // Baker's read barrier are used: | 
|  | 7713 | // | 
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7714 | //   root = obj.field; | 
|  | 7715 | //   temp = Thread::Current()->pReadBarrierMarkReg ## root.reg() | 
|  | 7716 | //   if (temp != null) { | 
|  | 7717 | //     root = temp(root) | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7718 | //   } | 
|  | 7719 |  | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7720 | // /* GcRoot<mirror::Object> */ root = *address | 
|  | 7721 | __ movl(root_reg, address); | 
|  | 7722 | if (fixup_label != nullptr) { | 
|  | 7723 | __ Bind(fixup_label); | 
|  | 7724 | } | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7725 | static_assert( | 
|  | 7726 | sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(GcRoot<mirror::Object>), | 
|  | 7727 | "art::mirror::CompressedReference<mirror::Object> and art::GcRoot<mirror::Object> " | 
|  | 7728 | "have different sizes."); | 
|  | 7729 | static_assert(sizeof(mirror::CompressedReference<mirror::Object>) == sizeof(int32_t), | 
|  | 7730 | "art::mirror::CompressedReference<mirror::Object> and int32_t " | 
|  | 7731 | "have different sizes."); | 
|  | 7732 |  | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7733 | // Slow path marking the GC root `root`. | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7734 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) ReadBarrierMarkSlowPathX86( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7735 | instruction, root, /* unpoison_ref_before_marking= */ false); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7736 | codegen_->AddSlowPath(slow_path); | 
|  | 7737 |  | 
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7738 | // Test the entrypoint (`Thread::Current()->pReadBarrierMarkReg ## root.reg()`). | 
|  | 7739 | const int32_t entry_point_offset = | 
| Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 7740 | Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(root.reg()); | 
| Roland Levillain | d966ce7 | 2017-02-09 16:20:14 +0000 | [diff] [blame] | 7741 | __ fs()->cmpl(Address::Absolute(entry_point_offset), Immediate(0)); | 
|  | 7742 | // The entrypoint is null when the GC is not marking. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7743 | __ j(kNotEqual, slow_path->GetEntryLabel()); | 
|  | 7744 | __ Bind(slow_path->GetExitLabel()); | 
|  | 7745 | } else { | 
|  | 7746 | // GC root loaded through a slow path for read barriers other | 
|  | 7747 | // than Baker's. | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7748 | // /* GcRoot<mirror::Object>* */ root = address | 
|  | 7749 | __ leal(root_reg, address); | 
|  | 7750 | if (fixup_label != nullptr) { | 
|  | 7751 | __ Bind(fixup_label); | 
|  | 7752 | } | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7753 | // /* mirror::Object* */ root = root->Read() | 
|  | 7754 | codegen_->GenerateReadBarrierForRootSlow(instruction, root, root); | 
|  | 7755 | } | 
|  | 7756 | } else { | 
|  | 7757 | // Plain GC root load with no read barrier. | 
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 7758 | // /* GcRoot<mirror::Object> */ root = *address | 
|  | 7759 | __ movl(root_reg, address); | 
|  | 7760 | if (fixup_label != nullptr) { | 
|  | 7761 | __ Bind(fixup_label); | 
|  | 7762 | } | 
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7763 | // Note that GC roots are not affected by heap poisoning, thus we | 
|  | 7764 | // do not have to unpoison `root_reg` here. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7765 | } | 
|  | 7766 | } | 
|  | 7767 |  | 
|  | 7768 | void CodeGeneratorX86::GenerateFieldLoadWithBakerReadBarrier(HInstruction* instruction, | 
|  | 7769 | Location ref, | 
|  | 7770 | Register obj, | 
|  | 7771 | uint32_t offset, | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7772 | bool needs_null_check) { | 
|  | 7773 | DCHECK(kEmitCompilerReadBarrier); | 
|  | 7774 | DCHECK(kUseBakerReadBarrier); | 
|  | 7775 |  | 
|  | 7776 | // /* HeapReference<Object> */ ref = *(obj + offset) | 
|  | 7777 | Address src(obj, offset); | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7778 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7779 | } | 
|  | 7780 |  | 
|  | 7781 | void CodeGeneratorX86::GenerateArrayLoadWithBakerReadBarrier(HInstruction* instruction, | 
|  | 7782 | Location ref, | 
|  | 7783 | Register obj, | 
|  | 7784 | uint32_t data_offset, | 
|  | 7785 | Location index, | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7786 | bool needs_null_check) { | 
|  | 7787 | DCHECK(kEmitCompilerReadBarrier); | 
|  | 7788 | DCHECK(kUseBakerReadBarrier); | 
|  | 7789 |  | 
| Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 7790 | static_assert( | 
|  | 7791 | sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t), | 
|  | 7792 | "art::mirror::HeapReference<art::mirror::Object> and int32_t have different sizes."); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7793 | // /* HeapReference<Object> */ ref = | 
|  | 7794 | //     *(obj + data_offset + index * sizeof(HeapReference<Object>)) | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 7795 | Address src = CodeGeneratorX86::ArrayAddress(obj, index, TIMES_4, data_offset); | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7796 | GenerateReferenceLoadWithBakerReadBarrier(instruction, ref, obj, src, needs_null_check); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7797 | } | 
|  | 7798 |  | 
|  | 7799 | void CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier(HInstruction* instruction, | 
|  | 7800 | Location ref, | 
|  | 7801 | Register obj, | 
|  | 7802 | const Address& src, | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7803 | bool needs_null_check, | 
|  | 7804 | bool always_update_field, | 
|  | 7805 | Register* temp) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7806 | DCHECK(kEmitCompilerReadBarrier); | 
|  | 7807 | DCHECK(kUseBakerReadBarrier); | 
|  | 7808 |  | 
|  | 7809 | // In slow path based read barriers, the read barrier call is | 
|  | 7810 | // inserted after the original load. However, in fast path based | 
|  | 7811 | // Baker's read barriers, we need to perform the load of | 
|  | 7812 | // mirror::Object::monitor_ *before* the original reference load. | 
|  | 7813 | // This load-load ordering is required by the read barrier. | 
|  | 7814 | // The fast path/slow path (for Baker's algorithm) should look like: | 
|  | 7815 | // | 
|  | 7816 | //   uint32_t rb_state = Lockword(obj->monitor_).ReadBarrierState(); | 
|  | 7817 | //   lfence;  // Load fence or artificial data dependency to prevent load-load reordering | 
|  | 7818 | //   HeapReference<Object> ref = *src;  // Original reference load. | 
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7819 | //   bool is_gray = (rb_state == ReadBarrier::GrayState()); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7820 | //   if (is_gray) { | 
|  | 7821 | //     ref = ReadBarrier::Mark(ref);  // Performed by runtime entrypoint slow path. | 
|  | 7822 | //   } | 
|  | 7823 | // | 
|  | 7824 | // Note: the original implementation in ReadBarrier::Barrier is | 
|  | 7825 | // slightly more complex as: | 
|  | 7826 | // - it implements the load-load fence using a data dependency on | 
| Roland Levillain | e3f43ac | 2016-01-19 15:07:47 +0000 | [diff] [blame] | 7827 | //   the high-bits of rb_state, which are expected to be all zeroes | 
|  | 7828 | //   (we use CodeGeneratorX86::GenerateMemoryBarrier instead here, | 
|  | 7829 | //   which is a no-op thanks to the x86 memory model); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7830 | // - it performs additional checks that we do not do here for | 
|  | 7831 | //   performance reasons. | 
|  | 7832 |  | 
|  | 7833 | Register ref_reg = ref.AsRegister<Register>(); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7834 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); | 
|  | 7835 |  | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7836 | // Given the numeric representation, it's enough to check the low bit of the rb_state. | 
| Roland Levillain | 14e5a29 | 2018-06-28 12:00:56 +0100 | [diff] [blame] | 7837 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); | 
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7838 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7839 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; | 
|  | 7840 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; | 
|  | 7841 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); | 
|  | 7842 |  | 
| Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 7843 | // if (rb_state == ReadBarrier::GrayState()) | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7844 | //   ref = ReadBarrier::Mark(ref); | 
|  | 7845 | // At this point, just do the "if" and make sure that flags are preserved until the branch. | 
|  | 7846 | __ testb(Address(obj, monitor_offset + gray_byte_position), Immediate(test_value)); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7847 | if (needs_null_check) { | 
|  | 7848 | MaybeRecordImplicitNullCheck(instruction); | 
|  | 7849 | } | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7850 |  | 
|  | 7851 | // Load fence to prevent load-load reordering. | 
|  | 7852 | // Note that this is a no-op, thanks to the x86 memory model. | 
|  | 7853 | GenerateMemoryBarrier(MemBarrierKind::kLoadAny); | 
|  | 7854 |  | 
|  | 7855 | // The actual reference load. | 
|  | 7856 | // /* HeapReference<Object> */ ref = *src | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7857 | __ movl(ref_reg, src);  // Flags are unaffected. | 
|  | 7858 |  | 
|  | 7859 | // Note: Reference unpoisoning modifies the flags, so we need to delay it after the branch. | 
|  | 7860 | // Slow path marking the object `ref` when it is gray. | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7861 | SlowPathCode* slow_path; | 
|  | 7862 | if (always_update_field) { | 
|  | 7863 | DCHECK(temp != nullptr); | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7864 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkAndUpdateFieldSlowPathX86( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7865 | instruction, ref, obj, src, /* unpoison_ref_before_marking= */ true, *temp); | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7866 | } else { | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7867 | slow_path = new (GetScopedAllocator()) ReadBarrierMarkSlowPathX86( | 
| Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 7868 | instruction, ref, /* unpoison_ref_before_marking= */ true); | 
| Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 7869 | } | 
| Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 7870 | AddSlowPath(slow_path); | 
|  | 7871 |  | 
|  | 7872 | // We have done the "if" of the gray bit check above, now branch based on the flags. | 
|  | 7873 | __ j(kNotZero, slow_path->GetEntryLabel()); | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7874 |  | 
|  | 7875 | // Object* ref = ref_addr->AsMirrorPtr() | 
|  | 7876 | __ MaybeUnpoisonHeapReference(ref_reg); | 
|  | 7877 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7878 | __ Bind(slow_path->GetExitLabel()); | 
|  | 7879 | } | 
|  | 7880 |  | 
|  | 7881 | void CodeGeneratorX86::GenerateReadBarrierSlow(HInstruction* instruction, | 
|  | 7882 | Location out, | 
|  | 7883 | Location ref, | 
|  | 7884 | Location obj, | 
|  | 7885 | uint32_t offset, | 
|  | 7886 | Location index) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7887 | DCHECK(kEmitCompilerReadBarrier); | 
|  | 7888 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7889 | // Insert a slow path based read barrier *after* the reference load. | 
|  | 7890 | // | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7891 | // If heap poisoning is enabled, the unpoisoning of the loaded | 
|  | 7892 | // reference will be carried out by the runtime within the slow | 
|  | 7893 | // path. | 
|  | 7894 | // | 
|  | 7895 | // Note that `ref` currently does not get unpoisoned (when heap | 
|  | 7896 | // poisoning is enabled), which is alright as the `ref` argument is | 
|  | 7897 | // not used by the artReadBarrierSlow entry point. | 
|  | 7898 | // | 
|  | 7899 | // TODO: Unpoison `ref` when it is used by artReadBarrierSlow. | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7900 | SlowPathCode* slow_path = new (GetScopedAllocator()) | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7901 | ReadBarrierForHeapReferenceSlowPathX86(instruction, out, ref, obj, offset, index); | 
|  | 7902 | AddSlowPath(slow_path); | 
|  | 7903 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7904 | __ jmp(slow_path->GetEntryLabel()); | 
|  | 7905 | __ Bind(slow_path->GetExitLabel()); | 
|  | 7906 | } | 
|  | 7907 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7908 | void CodeGeneratorX86::MaybeGenerateReadBarrierSlow(HInstruction* instruction, | 
|  | 7909 | Location out, | 
|  | 7910 | Location ref, | 
|  | 7911 | Location obj, | 
|  | 7912 | uint32_t offset, | 
|  | 7913 | Location index) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7914 | if (kEmitCompilerReadBarrier) { | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7915 | // Baker's read barriers shall be handled by the fast path | 
|  | 7916 | // (CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier). | 
|  | 7917 | DCHECK(!kUseBakerReadBarrier); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7918 | // If heap poisoning is enabled, unpoisoning will be taken care of | 
|  | 7919 | // by the runtime within the slow path. | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7920 | GenerateReadBarrierSlow(instruction, out, ref, obj, offset, index); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7921 | } else if (kPoisonHeapReferences) { | 
|  | 7922 | __ UnpoisonHeapReference(out.AsRegister<Register>()); | 
|  | 7923 | } | 
|  | 7924 | } | 
|  | 7925 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7926 | void CodeGeneratorX86::GenerateReadBarrierForRootSlow(HInstruction* instruction, | 
|  | 7927 | Location out, | 
|  | 7928 | Location root) { | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7929 | DCHECK(kEmitCompilerReadBarrier); | 
|  | 7930 |  | 
| Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 7931 | // Insert a slow path based read barrier *after* the GC root load. | 
|  | 7932 | // | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7933 | // Note that GC roots are not affected by heap poisoning, so we do | 
|  | 7934 | // not need to do anything special for this here. | 
|  | 7935 | SlowPathCode* slow_path = | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 7936 | new (GetScopedAllocator()) ReadBarrierForRootSlowPathX86(instruction, out, root); | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7937 | AddSlowPath(slow_path); | 
|  | 7938 |  | 
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 7939 | __ jmp(slow_path->GetEntryLabel()); | 
|  | 7940 | __ Bind(slow_path->GetExitLabel()); | 
|  | 7941 | } | 
|  | 7942 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7943 | void LocationsBuilderX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { | 
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7944 | // Nothing to do, this should be removed during prepare for register allocator. | 
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7945 | LOG(FATAL) << "Unreachable"; | 
|  | 7946 | } | 
|  | 7947 |  | 
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7948 | void InstructionCodeGeneratorX86::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) { | 
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7949 | // Nothing to do, this should be removed during prepare for register allocator. | 
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7950 | LOG(FATAL) << "Unreachable"; | 
|  | 7951 | } | 
|  | 7952 |  | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7953 | // Simple implementation of packed switch - generate cascaded compare/jumps. | 
|  | 7954 | void LocationsBuilderX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
|  | 7955 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 7956 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7957 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 7958 | } | 
|  | 7959 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7960 | void InstructionCodeGeneratorX86::GenPackedSwitchWithCompares(Register value_reg, | 
|  | 7961 | int32_t lower_bound, | 
|  | 7962 | uint32_t num_entries, | 
|  | 7963 | HBasicBlock* switch_block, | 
|  | 7964 | HBasicBlock* default_block) { | 
|  | 7965 | // Figure out the correct compare values and jump conditions. | 
|  | 7966 | // Handle the first compare/branch as a special case because it might | 
|  | 7967 | // jump to the default case. | 
|  | 7968 | DCHECK_GT(num_entries, 2u); | 
|  | 7969 | Condition first_condition; | 
|  | 7970 | uint32_t index; | 
|  | 7971 | const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors(); | 
|  | 7972 | if (lower_bound != 0) { | 
|  | 7973 | first_condition = kLess; | 
|  | 7974 | __ cmpl(value_reg, Immediate(lower_bound)); | 
|  | 7975 | __ j(first_condition, codegen_->GetLabelOf(default_block)); | 
|  | 7976 | __ j(kEqual, codegen_->GetLabelOf(successors[0])); | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 7977 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 7978 | index = 1; | 
|  | 7979 | } else { | 
|  | 7980 | // Handle all the compare/jumps below. | 
|  | 7981 | first_condition = kBelow; | 
|  | 7982 | index = 0; | 
|  | 7983 | } | 
|  | 7984 |  | 
|  | 7985 | // Handle the rest of the compare/jumps. | 
|  | 7986 | for (; index + 1 < num_entries; index += 2) { | 
|  | 7987 | int32_t compare_to_value = lower_bound + index + 1; | 
|  | 7988 | __ cmpl(value_reg, Immediate(compare_to_value)); | 
|  | 7989 | // Jump to successors[index] if value < case_value[index]. | 
|  | 7990 | __ j(first_condition, codegen_->GetLabelOf(successors[index])); | 
|  | 7991 | // Jump to successors[index + 1] if value == case_value[index + 1]. | 
|  | 7992 | __ j(kEqual, codegen_->GetLabelOf(successors[index + 1])); | 
|  | 7993 | } | 
|  | 7994 |  | 
|  | 7995 | if (index != num_entries) { | 
|  | 7996 | // There are an odd number of entries. Handle the last one. | 
|  | 7997 | DCHECK_EQ(index + 1, num_entries); | 
|  | 7998 | __ cmpl(value_reg, Immediate(lower_bound + index)); | 
|  | 7999 | __ j(kEqual, codegen_->GetLabelOf(successors[index])); | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8000 | } | 
|  | 8001 |  | 
|  | 8002 | // And the default for any other value. | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8003 | if (!codegen_->GoesToNextBlock(switch_block, default_block)) { | 
|  | 8004 | __ jmp(codegen_->GetLabelOf(default_block)); | 
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 8005 | } | 
|  | 8006 | } | 
|  | 8007 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8008 | void InstructionCodeGeneratorX86::VisitPackedSwitch(HPackedSwitch* switch_instr) { | 
|  | 8009 | int32_t lower_bound = switch_instr->GetStartValue(); | 
|  | 8010 | uint32_t num_entries = switch_instr->GetNumEntries(); | 
|  | 8011 | LocationSummary* locations = switch_instr->GetLocations(); | 
|  | 8012 | Register value_reg = locations->InAt(0).AsRegister<Register>(); | 
|  | 8013 |  | 
|  | 8014 | GenPackedSwitchWithCompares(value_reg, | 
|  | 8015 | lower_bound, | 
|  | 8016 | num_entries, | 
|  | 8017 | switch_instr->GetBlock(), | 
|  | 8018 | switch_instr->GetDefaultBlock()); | 
|  | 8019 | } | 
|  | 8020 |  | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8021 | void LocationsBuilderX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { | 
|  | 8022 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8023 | new (GetGraph()->GetAllocator()) LocationSummary(switch_instr, LocationSummary::kNoCall); | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8024 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 8025 |  | 
|  | 8026 | // Constant area pointer. | 
|  | 8027 | locations->SetInAt(1, Location::RequiresRegister()); | 
|  | 8028 |  | 
|  | 8029 | // And the temporary we need. | 
|  | 8030 | locations->AddTemp(Location::RequiresRegister()); | 
|  | 8031 | } | 
|  | 8032 |  | 
|  | 8033 | void InstructionCodeGeneratorX86::VisitX86PackedSwitch(HX86PackedSwitch* switch_instr) { | 
|  | 8034 | int32_t lower_bound = switch_instr->GetStartValue(); | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8035 | uint32_t num_entries = switch_instr->GetNumEntries(); | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8036 | LocationSummary* locations = switch_instr->GetLocations(); | 
|  | 8037 | Register value_reg = locations->InAt(0).AsRegister<Register>(); | 
|  | 8038 | HBasicBlock* default_block = switch_instr->GetDefaultBlock(); | 
|  | 8039 |  | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8040 | if (num_entries <= kPackedSwitchJumpTableThreshold) { | 
|  | 8041 | GenPackedSwitchWithCompares(value_reg, | 
|  | 8042 | lower_bound, | 
|  | 8043 | num_entries, | 
|  | 8044 | switch_instr->GetBlock(), | 
|  | 8045 | default_block); | 
|  | 8046 | return; | 
|  | 8047 | } | 
|  | 8048 |  | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8049 | // Optimizing has a jump area. | 
|  | 8050 | Register temp_reg = locations->GetTemp(0).AsRegister<Register>(); | 
|  | 8051 | Register constant_area = locations->InAt(1).AsRegister<Register>(); | 
|  | 8052 |  | 
|  | 8053 | // Remove the bias, if needed. | 
|  | 8054 | if (lower_bound != 0) { | 
|  | 8055 | __ leal(temp_reg, Address(value_reg, -lower_bound)); | 
|  | 8056 | value_reg = temp_reg; | 
|  | 8057 | } | 
|  | 8058 |  | 
|  | 8059 | // Is the value in range? | 
| Vladimir Marko | f3e0ee2 | 2015-12-17 15:23:13 +0000 | [diff] [blame] | 8060 | DCHECK_GE(num_entries, 1u); | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8061 | __ cmpl(value_reg, Immediate(num_entries - 1)); | 
|  | 8062 | __ j(kAbove, codegen_->GetLabelOf(default_block)); | 
|  | 8063 |  | 
|  | 8064 | // We are in the range of the table. | 
|  | 8065 | // Load (target-constant_area) from the jump table, indexing by the value. | 
|  | 8066 | __ movl(temp_reg, codegen_->LiteralCaseTable(switch_instr, constant_area, value_reg)); | 
|  | 8067 |  | 
|  | 8068 | // Compute the actual target address by adding in constant_area. | 
|  | 8069 | __ addl(temp_reg, constant_area); | 
|  | 8070 |  | 
|  | 8071 | // And jump. | 
|  | 8072 | __ jmp(temp_reg); | 
|  | 8073 | } | 
|  | 8074 |  | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8075 | void LocationsBuilderX86::VisitX86ComputeBaseMethodAddress( | 
|  | 8076 | HX86ComputeBaseMethodAddress* insn) { | 
|  | 8077 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8078 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8079 | locations->SetOut(Location::RequiresRegister()); | 
|  | 8080 | } | 
|  | 8081 |  | 
|  | 8082 | void InstructionCodeGeneratorX86::VisitX86ComputeBaseMethodAddress( | 
|  | 8083 | HX86ComputeBaseMethodAddress* insn) { | 
|  | 8084 | LocationSummary* locations = insn->GetLocations(); | 
|  | 8085 | Register reg = locations->Out().AsRegister<Register>(); | 
|  | 8086 |  | 
|  | 8087 | // Generate call to next instruction. | 
|  | 8088 | Label next_instruction; | 
|  | 8089 | __ call(&next_instruction); | 
|  | 8090 | __ Bind(&next_instruction); | 
|  | 8091 |  | 
|  | 8092 | // Remember this offset for later use with constant area. | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8093 | codegen_->AddMethodAddressOffset(insn, GetAssembler()->CodeSize()); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8094 |  | 
|  | 8095 | // Grab the return address off the stack. | 
|  | 8096 | __ popl(reg); | 
|  | 8097 | } | 
|  | 8098 |  | 
|  | 8099 | void LocationsBuilderX86::VisitX86LoadFromConstantTable( | 
|  | 8100 | HX86LoadFromConstantTable* insn) { | 
|  | 8101 | LocationSummary* locations = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8102 | new (GetGraph()->GetAllocator()) LocationSummary(insn, LocationSummary::kNoCall); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8103 |  | 
|  | 8104 | locations->SetInAt(0, Location::RequiresRegister()); | 
|  | 8105 | locations->SetInAt(1, Location::ConstantLocation(insn->GetConstant())); | 
|  | 8106 |  | 
|  | 8107 | // If we don't need to be materialized, we only need the inputs to be set. | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8108 | if (insn->IsEmittedAtUseSite()) { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8109 | return; | 
|  | 8110 | } | 
|  | 8111 |  | 
|  | 8112 | switch (insn->GetType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8113 | case DataType::Type::kFloat32: | 
|  | 8114 | case DataType::Type::kFloat64: | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8115 | locations->SetOut(Location::RequiresFpuRegister()); | 
|  | 8116 | break; | 
|  | 8117 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8118 | case DataType::Type::kInt32: | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8119 | locations->SetOut(Location::RequiresRegister()); | 
|  | 8120 | break; | 
|  | 8121 |  | 
|  | 8122 | default: | 
|  | 8123 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); | 
|  | 8124 | } | 
|  | 8125 | } | 
|  | 8126 |  | 
|  | 8127 | void InstructionCodeGeneratorX86::VisitX86LoadFromConstantTable(HX86LoadFromConstantTable* insn) { | 
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 8128 | if (insn->IsEmittedAtUseSite()) { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8129 | return; | 
|  | 8130 | } | 
|  | 8131 |  | 
|  | 8132 | LocationSummary* locations = insn->GetLocations(); | 
|  | 8133 | Location out = locations->Out(); | 
|  | 8134 | Register const_area = locations->InAt(0).AsRegister<Register>(); | 
|  | 8135 | HConstant *value = insn->GetConstant(); | 
|  | 8136 |  | 
|  | 8137 | switch (insn->GetType()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8138 | case DataType::Type::kFloat32: | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8139 | __ movss(out.AsFpuRegister<XmmRegister>(), | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8140 | codegen_->LiteralFloatAddress( | 
|  | 8141 | value->AsFloatConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8142 | break; | 
|  | 8143 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8144 | case DataType::Type::kFloat64: | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8145 | __ movsd(out.AsFpuRegister<XmmRegister>(), | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8146 | codegen_->LiteralDoubleAddress( | 
|  | 8147 | value->AsDoubleConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8148 | break; | 
|  | 8149 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8150 | case DataType::Type::kInt32: | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8151 | __ movl(out.AsRegister<Register>(), | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8152 | codegen_->LiteralInt32Address( | 
|  | 8153 | value->AsIntConstant()->GetValue(), insn->GetBaseMethodAddress(), const_area)); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8154 | break; | 
|  | 8155 |  | 
|  | 8156 | default: | 
|  | 8157 | LOG(FATAL) << "Unsupported x86 constant area type " << insn->GetType(); | 
|  | 8158 | } | 
|  | 8159 | } | 
|  | 8160 |  | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8161 | /** | 
|  | 8162 | * Class to handle late fixup of offsets into constant area. | 
|  | 8163 | */ | 
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 8164 | class RIPFixup : public AssemblerFixup, public ArenaObject<kArenaAllocCodeGenerator> { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8165 | public: | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8166 | RIPFixup(CodeGeneratorX86& codegen, | 
|  | 8167 | HX86ComputeBaseMethodAddress* base_method_address, | 
|  | 8168 | size_t offset) | 
|  | 8169 | : codegen_(&codegen), | 
|  | 8170 | base_method_address_(base_method_address), | 
|  | 8171 | offset_into_constant_area_(offset) {} | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8172 |  | 
|  | 8173 | protected: | 
|  | 8174 | void SetOffset(size_t offset) { offset_into_constant_area_ = offset; } | 
|  | 8175 |  | 
|  | 8176 | CodeGeneratorX86* codegen_; | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8177 | HX86ComputeBaseMethodAddress* base_method_address_; | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8178 |  | 
|  | 8179 | private: | 
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 8180 | void Process(const MemoryRegion& region, int pos) override { | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8181 | // Patch the correct offset for the instruction.  The place to patch is the | 
|  | 8182 | // last 4 bytes of the instruction. | 
|  | 8183 | // The value to patch is the distance from the offset in the constant area | 
|  | 8184 | // from the address computed by the HX86ComputeBaseMethodAddress instruction. | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8185 | int32_t constant_offset = codegen_->ConstantAreaStart() + offset_into_constant_area_; | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8186 | int32_t relative_position = | 
|  | 8187 | constant_offset - codegen_->GetMethodAddressOffset(base_method_address_); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8188 |  | 
|  | 8189 | // Patch in the right value. | 
|  | 8190 | region.StoreUnaligned<int32_t>(pos - 4, relative_position); | 
|  | 8191 | } | 
|  | 8192 |  | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8193 | // Location in constant area that the fixup refers to. | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8194 | int32_t offset_into_constant_area_; | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8195 | }; | 
|  | 8196 |  | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8197 | /** | 
|  | 8198 | * Class to handle late fixup of offsets to a jump table that will be created in the | 
|  | 8199 | * constant area. | 
|  | 8200 | */ | 
|  | 8201 | class JumpTableRIPFixup : public RIPFixup { | 
|  | 8202 | public: | 
|  | 8203 | JumpTableRIPFixup(CodeGeneratorX86& codegen, HX86PackedSwitch* switch_instr) | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8204 | : RIPFixup(codegen, switch_instr->GetBaseMethodAddress(), static_cast<size_t>(-1)), | 
|  | 8205 | switch_instr_(switch_instr) {} | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8206 |  | 
|  | 8207 | void CreateJumpTable() { | 
|  | 8208 | X86Assembler* assembler = codegen_->GetAssembler(); | 
|  | 8209 |  | 
|  | 8210 | // Ensure that the reference to the jump table has the correct offset. | 
|  | 8211 | const int32_t offset_in_constant_table = assembler->ConstantAreaSize(); | 
|  | 8212 | SetOffset(offset_in_constant_table); | 
|  | 8213 |  | 
|  | 8214 | // The label values in the jump table are computed relative to the | 
|  | 8215 | // instruction addressing the constant area. | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8216 | const int32_t relative_offset = codegen_->GetMethodAddressOffset(base_method_address_); | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8217 |  | 
|  | 8218 | // Populate the jump table with the correct values for the jump table. | 
|  | 8219 | int32_t num_entries = switch_instr_->GetNumEntries(); | 
|  | 8220 | HBasicBlock* block = switch_instr_->GetBlock(); | 
|  | 8221 | const ArenaVector<HBasicBlock*>& successors = block->GetSuccessors(); | 
|  | 8222 | // The value that we want is the target offset - the position of the table. | 
|  | 8223 | for (int32_t i = 0; i < num_entries; i++) { | 
|  | 8224 | HBasicBlock* b = successors[i]; | 
|  | 8225 | Label* l = codegen_->GetLabelOf(b); | 
|  | 8226 | DCHECK(l->IsBound()); | 
|  | 8227 | int32_t offset_to_block = l->Position() - relative_offset; | 
|  | 8228 | assembler->AppendInt32(offset_to_block); | 
|  | 8229 | } | 
|  | 8230 | } | 
|  | 8231 |  | 
|  | 8232 | private: | 
|  | 8233 | const HX86PackedSwitch* switch_instr_; | 
|  | 8234 | }; | 
|  | 8235 |  | 
|  | 8236 | void CodeGeneratorX86::Finalize(CodeAllocator* allocator) { | 
|  | 8237 | // Generate the constant area if needed. | 
|  | 8238 | X86Assembler* assembler = GetAssembler(); | 
|  | 8239 | if (!assembler->IsConstantAreaEmpty() || !fixups_to_jump_tables_.empty()) { | 
|  | 8240 | // Align to 4 byte boundary to reduce cache misses, as the data is 4 and 8 | 
|  | 8241 | // byte values. | 
|  | 8242 | assembler->Align(4, 0); | 
|  | 8243 | constant_area_start_ = assembler->CodeSize(); | 
|  | 8244 |  | 
|  | 8245 | // Populate any jump tables. | 
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8246 | for (JumpTableRIPFixup* jump_table : fixups_to_jump_tables_) { | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8247 | jump_table->CreateJumpTable(); | 
|  | 8248 | } | 
|  | 8249 |  | 
|  | 8250 | // And now add the constant area to the generated code. | 
|  | 8251 | assembler->AddConstantArea(); | 
|  | 8252 | } | 
|  | 8253 |  | 
|  | 8254 | // And finish up. | 
|  | 8255 | CodeGenerator::Finalize(allocator); | 
|  | 8256 | } | 
|  | 8257 |  | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8258 | Address CodeGeneratorX86::LiteralDoubleAddress(double v, | 
|  | 8259 | HX86ComputeBaseMethodAddress* method_base, | 
|  | 8260 | Register reg) { | 
|  | 8261 | AssemblerFixup* fixup = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8262 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddDouble(v)); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8263 | return Address(reg, kDummy32BitOffset, fixup); | 
|  | 8264 | } | 
|  | 8265 |  | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8266 | Address CodeGeneratorX86::LiteralFloatAddress(float v, | 
|  | 8267 | HX86ComputeBaseMethodAddress* method_base, | 
|  | 8268 | Register reg) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8269 | AssemblerFixup* fixup = | 
|  | 8270 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddFloat(v)); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8271 | return Address(reg, kDummy32BitOffset, fixup); | 
|  | 8272 | } | 
|  | 8273 |  | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8274 | Address CodeGeneratorX86::LiteralInt32Address(int32_t v, | 
|  | 8275 | HX86ComputeBaseMethodAddress* method_base, | 
|  | 8276 | Register reg) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8277 | AssemblerFixup* fixup = | 
|  | 8278 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt32(v)); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8279 | return Address(reg, kDummy32BitOffset, fixup); | 
|  | 8280 | } | 
|  | 8281 |  | 
| Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 8282 | Address CodeGeneratorX86::LiteralInt64Address(int64_t v, | 
|  | 8283 | HX86ComputeBaseMethodAddress* method_base, | 
|  | 8284 | Register reg) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8285 | AssemblerFixup* fixup = | 
|  | 8286 | new (GetGraph()->GetAllocator()) RIPFixup(*this, method_base, __ AddInt64(v)); | 
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 8287 | return Address(reg, kDummy32BitOffset, fixup); | 
|  | 8288 | } | 
|  | 8289 |  | 
| Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 8290 | void CodeGeneratorX86::Load32BitValue(Register dest, int32_t value) { | 
|  | 8291 | if (value == 0) { | 
|  | 8292 | __ xorl(dest, dest); | 
|  | 8293 | } else { | 
|  | 8294 | __ movl(dest, Immediate(value)); | 
|  | 8295 | } | 
|  | 8296 | } | 
|  | 8297 |  | 
|  | 8298 | void CodeGeneratorX86::Compare32BitValue(Register dest, int32_t value) { | 
|  | 8299 | if (value == 0) { | 
|  | 8300 | __ testl(dest, dest); | 
|  | 8301 | } else { | 
|  | 8302 | __ cmpl(dest, Immediate(value)); | 
|  | 8303 | } | 
|  | 8304 | } | 
|  | 8305 |  | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8306 | void CodeGeneratorX86::GenerateIntCompare(Location lhs, Location rhs) { | 
|  | 8307 | Register lhs_reg = lhs.AsRegister<Register>(); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8308 | GenerateIntCompare(lhs_reg, rhs); | 
|  | 8309 | } | 
|  | 8310 |  | 
|  | 8311 | void CodeGeneratorX86::GenerateIntCompare(Register lhs, Location rhs) { | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8312 | if (rhs.IsConstant()) { | 
|  | 8313 | int32_t value = CodeGenerator::GetInt32ValueOf(rhs.GetConstant()); | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8314 | Compare32BitValue(lhs, value); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8315 | } else if (rhs.IsStackSlot()) { | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8316 | __ cmpl(lhs, Address(ESP, rhs.GetStackIndex())); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8317 | } else { | 
| jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 8318 | __ cmpl(lhs, rhs.AsRegister<Register>()); | 
| Vladimir Marko | 56f4bdd | 2016-09-16 11:32:36 +0100 | [diff] [blame] | 8319 | } | 
|  | 8320 | } | 
|  | 8321 |  | 
|  | 8322 | Address CodeGeneratorX86::ArrayAddress(Register obj, | 
|  | 8323 | Location index, | 
|  | 8324 | ScaleFactor scale, | 
|  | 8325 | uint32_t data_offset) { | 
|  | 8326 | return index.IsConstant() ? | 
|  | 8327 | Address(obj, (index.GetConstant()->AsIntConstant()->GetValue() << scale) + data_offset) : | 
|  | 8328 | Address(obj, index.AsRegister<Register>(), scale, data_offset); | 
|  | 8329 | } | 
|  | 8330 |  | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8331 | Address CodeGeneratorX86::LiteralCaseTable(HX86PackedSwitch* switch_instr, | 
|  | 8332 | Register reg, | 
|  | 8333 | Register value) { | 
|  | 8334 | // Create a fixup to be used to create and address the jump table. | 
|  | 8335 | JumpTableRIPFixup* table_fixup = | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8336 | new (GetGraph()->GetAllocator()) JumpTableRIPFixup(*this, switch_instr); | 
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 8337 |  | 
|  | 8338 | // We have to populate the jump tables. | 
|  | 8339 | fixups_to_jump_tables_.push_back(table_fixup); | 
|  | 8340 |  | 
|  | 8341 | // We want a scaled address, as we are extracting the correct offset from the table. | 
|  | 8342 | return Address(reg, value, TIMES_4, kDummy32BitOffset, table_fixup); | 
|  | 8343 | } | 
|  | 8344 |  | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8345 | // TODO: target as memory. | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8346 | void CodeGeneratorX86::MoveFromReturnRegister(Location target, DataType::Type type) { | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8347 | if (!target.IsValid()) { | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8348 | DCHECK_EQ(type, DataType::Type::kVoid); | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8349 | return; | 
|  | 8350 | } | 
|  | 8351 |  | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8352 | DCHECK_NE(type, DataType::Type::kVoid); | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8353 |  | 
|  | 8354 | Location return_loc = InvokeDexCallingConventionVisitorX86().GetReturnLocation(type); | 
|  | 8355 | if (target.Equals(return_loc)) { | 
|  | 8356 | return; | 
|  | 8357 | } | 
|  | 8358 |  | 
|  | 8359 | // TODO: Consider pairs in the parallel move resolver, then this could be nicely merged | 
|  | 8360 | //       with the else branch. | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8361 | if (type == DataType::Type::kInt64) { | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8362 | HParallelMove parallel_move(GetGraph()->GetAllocator()); | 
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 8363 | parallel_move.AddMove(return_loc.ToLow(), target.ToLow(), DataType::Type::kInt32, nullptr); | 
|  | 8364 | parallel_move.AddMove(return_loc.ToHigh(), target.ToHigh(), DataType::Type::kInt32, nullptr); | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8365 | GetMoveResolver()->EmitNativeCode(¶llel_move); | 
|  | 8366 | } else { | 
|  | 8367 | // Let the parallel move resolver take care of all of this. | 
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 8368 | HParallelMove parallel_move(GetGraph()->GetAllocator()); | 
| Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 8369 | parallel_move.AddMove(return_loc, target, type, nullptr); | 
|  | 8370 | GetMoveResolver()->EmitNativeCode(¶llel_move); | 
|  | 8371 | } | 
|  | 8372 | } | 
|  | 8373 |  | 
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8374 | void CodeGeneratorX86::PatchJitRootUse(uint8_t* code, | 
|  | 8375 | const uint8_t* roots_data, | 
|  | 8376 | const PatchInfo<Label>& info, | 
|  | 8377 | uint64_t index_in_table) const { | 
|  | 8378 | uint32_t code_offset = info.label.Position() - kLabelPositionToLiteralOffsetAdjustment; | 
|  | 8379 | uintptr_t address = | 
|  | 8380 | reinterpret_cast<uintptr_t>(roots_data) + index_in_table * sizeof(GcRoot<mirror::Object>); | 
| Andreas Gampe | c55bb39 | 2018-09-21 00:02:02 +0000 | [diff] [blame] | 8381 | using unaligned_uint32_t __attribute__((__aligned__(1))) = uint32_t; | 
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8382 | reinterpret_cast<unaligned_uint32_t*>(code + code_offset)[0] = | 
|  | 8383 | dchecked_integral_cast<uint32_t>(address); | 
|  | 8384 | } | 
|  | 8385 |  | 
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8386 | void CodeGeneratorX86::EmitJitRootPatches(uint8_t* code, const uint8_t* roots_data) { | 
|  | 8387 | for (const PatchInfo<Label>& info : jit_string_patches_) { | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8388 | StringReference string_reference(info.target_dex_file, dex::StringIndex(info.offset_or_index)); | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8389 | uint64_t index_in_table = GetJitStringRootIndex(string_reference); | 
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8390 | PatchJitRootUse(code, roots_data, info, index_in_table); | 
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 8391 | } | 
|  | 8392 |  | 
|  | 8393 | for (const PatchInfo<Label>& info : jit_class_patches_) { | 
| Vladimir Marko | 59eb30f | 2018-02-20 11:52:34 +0000 | [diff] [blame] | 8394 | TypeReference type_reference(info.target_dex_file, dex::TypeIndex(info.offset_or_index)); | 
| Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 8395 | uint64_t index_in_table = GetJitClassRootIndex(type_reference); | 
| Vladimir Marko | 7d157fc | 2017-05-10 16:29:23 +0100 | [diff] [blame] | 8396 | PatchJitRootUse(code, roots_data, info, index_in_table); | 
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 8397 | } | 
|  | 8398 | } | 
|  | 8399 |  | 
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 8400 | void LocationsBuilderX86::VisitIntermediateAddress(HIntermediateAddress* instruction | 
|  | 8401 | ATTRIBUTE_UNUSED) { | 
|  | 8402 | LOG(FATAL) << "Unreachable"; | 
|  | 8403 | } | 
|  | 8404 |  | 
|  | 8405 | void InstructionCodeGeneratorX86::VisitIntermediateAddress(HIntermediateAddress* instruction | 
|  | 8406 | ATTRIBUTE_UNUSED) { | 
|  | 8407 | LOG(FATAL) << "Unreachable"; | 
|  | 8408 | } | 
|  | 8409 |  | 
| Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 8410 | #undef __ | 
|  | 8411 |  | 
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 8412 | }  // namespace x86 | 
|  | 8413 | }  // namespace art |