Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 "intrinsics_x86.h" |
| 18 | |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 19 | #include <limits> |
| 20 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 21 | #include "arch/x86/instruction_set_features_x86.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 22 | #include "art_method.h" |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 23 | #include "base/bit_utils.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 24 | #include "code_generator_x86.h" |
| 25 | #include "entrypoints/quick/quick_entrypoints.h" |
Andreas Gampe | 09659c2 | 2017-09-18 18:23:32 -0700 | [diff] [blame] | 26 | #include "heap_poisoning.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 27 | #include "intrinsics.h" |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 28 | #include "intrinsics_utils.h" |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 29 | #include "lock_word.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 30 | #include "mirror/array-inl.h" |
Andreas Gampe | c15a2f4 | 2017-04-21 12:09:39 -0700 | [diff] [blame] | 31 | #include "mirror/object_array-inl.h" |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 32 | #include "mirror/reference.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 33 | #include "mirror/string.h" |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 34 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 35 | #include "thread-current-inl.h" |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 36 | #include "utils/x86/assembler_x86.h" |
| 37 | #include "utils/x86/constants_x86.h" |
| 38 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame^] | 39 | namespace art { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 40 | |
| 41 | namespace x86 { |
| 42 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 43 | IntrinsicLocationsBuilderX86::IntrinsicLocationsBuilderX86(CodeGeneratorX86* codegen) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 44 | : allocator_(codegen->GetGraph()->GetAllocator()), |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 45 | codegen_(codegen) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 49 | X86Assembler* IntrinsicCodeGeneratorX86::GetAssembler() { |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 50 | return down_cast<X86Assembler*>(codegen_->GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | ArenaAllocator* IntrinsicCodeGeneratorX86::GetAllocator() { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 54 | return codegen_->GetGraph()->GetAllocator(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | bool IntrinsicLocationsBuilderX86::TryDispatch(HInvoke* invoke) { |
| 58 | Dispatch(invoke); |
| 59 | LocationSummary* res = invoke->GetLocations(); |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 60 | if (res == nullptr) { |
| 61 | return false; |
| 62 | } |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 63 | return res->Intrinsified(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 64 | } |
| 65 | |
Roland Levillain | ec525fc | 2015-04-28 15:50:20 +0100 | [diff] [blame] | 66 | static void MoveArguments(HInvoke* invoke, CodeGeneratorX86* codegen) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 67 | InvokeDexCallingConventionVisitorX86 calling_convention_visitor; |
Roland Levillain | ec525fc | 2015-04-28 15:50:20 +0100 | [diff] [blame] | 68 | IntrinsicVisitor::MoveArguments(invoke, codegen, &calling_convention_visitor); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 69 | } |
| 70 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 71 | using IntrinsicSlowPathX86 = IntrinsicSlowPath<InvokeDexCallingConventionVisitorX86>; |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 72 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 73 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 74 | #define __ down_cast<X86Assembler*>(codegen->GetAssembler())-> // NOLINT |
| 75 | |
| 76 | // Slow path implementing the SystemArrayCopy intrinsic copy loop with read barriers. |
| 77 | class ReadBarrierSystemArrayCopySlowPathX86 : public SlowPathCode { |
| 78 | public: |
| 79 | explicit ReadBarrierSystemArrayCopySlowPathX86(HInstruction* instruction) |
| 80 | : SlowPathCode(instruction) { |
| 81 | DCHECK(kEmitCompilerReadBarrier); |
| 82 | DCHECK(kUseBakerReadBarrier); |
| 83 | } |
| 84 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 85 | void EmitNativeCode(CodeGenerator* codegen) override { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 86 | CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen); |
| 87 | LocationSummary* locations = instruction_->GetLocations(); |
| 88 | DCHECK(locations->CanCall()); |
| 89 | DCHECK(instruction_->IsInvokeStaticOrDirect()) |
| 90 | << "Unexpected instruction in read barrier arraycopy slow path: " |
| 91 | << instruction_->DebugName(); |
| 92 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 93 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kSystemArrayCopy); |
| 94 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 95 | int32_t element_size = DataType::Size(DataType::Type::kReference); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 96 | uint32_t offset = mirror::Array::DataOffset(element_size).Uint32Value(); |
| 97 | |
| 98 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 99 | Location src_pos = locations->InAt(1); |
| 100 | Register dest = locations->InAt(2).AsRegister<Register>(); |
| 101 | Location dest_pos = locations->InAt(3); |
| 102 | Location length = locations->InAt(4); |
| 103 | Location temp1_loc = locations->GetTemp(0); |
| 104 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 105 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 106 | Register temp3 = locations->GetTemp(2).AsRegister<Register>(); |
| 107 | |
| 108 | __ Bind(GetEntryLabel()); |
| 109 | // In this code path, registers `temp1`, `temp2`, and `temp3` |
| 110 | // (resp.) are not used for the base source address, the base |
| 111 | // destination address, and the end source address (resp.), as in |
| 112 | // other SystemArrayCopy intrinsic code paths. Instead they are |
| 113 | // (resp.) used for: |
| 114 | // - the loop index (`i`); |
| 115 | // - the source index (`src_index`) and the loaded (source) |
| 116 | // reference (`value`); and |
| 117 | // - the destination index (`dest_index`). |
| 118 | |
| 119 | // i = 0 |
| 120 | __ xorl(temp1, temp1); |
| 121 | NearLabel loop; |
| 122 | __ Bind(&loop); |
| 123 | // value = src_array[i + src_pos] |
| 124 | if (src_pos.IsConstant()) { |
| 125 | int32_t constant = src_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 126 | int32_t adjusted_offset = offset + constant * element_size; |
| 127 | __ movl(temp2, Address(src, temp1, ScaleFactor::TIMES_4, adjusted_offset)); |
| 128 | } else { |
| 129 | __ leal(temp2, Address(src_pos.AsRegister<Register>(), temp1, ScaleFactor::TIMES_1, 0)); |
| 130 | __ movl(temp2, Address(src, temp2, ScaleFactor::TIMES_4, offset)); |
| 131 | } |
| 132 | __ MaybeUnpoisonHeapReference(temp2); |
| 133 | // TODO: Inline the mark bit check before calling the runtime? |
| 134 | // value = ReadBarrier::Mark(value) |
| 135 | // No need to save live registers; it's taken care of by the |
| 136 | // entrypoint. Also, there is no need to update the stack mask, |
| 137 | // as this runtime call will not trigger a garbage collection. |
| 138 | // (See ReadBarrierMarkSlowPathX86::EmitNativeCode for more |
| 139 | // explanations.) |
| 140 | DCHECK_NE(temp2, ESP); |
| 141 | DCHECK(0 <= temp2 && temp2 < kNumberOfCpuRegisters) << temp2; |
Roland Levillain | 97c4646 | 2017-05-11 14:04:03 +0100 | [diff] [blame] | 142 | int32_t entry_point_offset = Thread::ReadBarrierMarkEntryPointsOffset<kX86PointerSize>(temp2); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 143 | // This runtime call does not require a stack map. |
| 144 | x86_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 145 | __ MaybePoisonHeapReference(temp2); |
| 146 | // dest_array[i + dest_pos] = value |
| 147 | if (dest_pos.IsConstant()) { |
| 148 | int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 149 | int32_t adjusted_offset = offset + constant * element_size; |
| 150 | __ movl(Address(dest, temp1, ScaleFactor::TIMES_4, adjusted_offset), temp2); |
| 151 | } else { |
| 152 | __ leal(temp3, Address(dest_pos.AsRegister<Register>(), temp1, ScaleFactor::TIMES_1, 0)); |
| 153 | __ movl(Address(dest, temp3, ScaleFactor::TIMES_4, offset), temp2); |
| 154 | } |
| 155 | // ++i |
| 156 | __ addl(temp1, Immediate(1)); |
| 157 | // if (i != length) goto loop |
| 158 | x86_codegen->GenerateIntCompare(temp1_loc, length); |
| 159 | __ j(kNotEqual, &loop); |
| 160 | __ jmp(GetExitLabel()); |
| 161 | } |
| 162 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 163 | const char* GetDescription() const override { return "ReadBarrierSystemArrayCopySlowPathX86"; } |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 164 | |
| 165 | private: |
| 166 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierSystemArrayCopySlowPathX86); |
| 167 | }; |
| 168 | |
| 169 | #undef __ |
| 170 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 171 | #define __ assembler-> |
| 172 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 173 | static void CreateFPToIntLocations(ArenaAllocator* allocator, HInvoke* invoke, bool is64bit) { |
| 174 | LocationSummary* locations = |
| 175 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 176 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 177 | locations->SetOut(Location::RequiresRegister()); |
| 178 | if (is64bit) { |
| 179 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 180 | } |
| 181 | } |
| 182 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 183 | static void CreateIntToFPLocations(ArenaAllocator* allocator, HInvoke* invoke, bool is64bit) { |
| 184 | LocationSummary* locations = |
| 185 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 186 | locations->SetInAt(0, Location::RequiresRegister()); |
| 187 | locations->SetOut(Location::RequiresFpuRegister()); |
| 188 | if (is64bit) { |
| 189 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 190 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | static void MoveFPToInt(LocationSummary* locations, bool is64bit, X86Assembler* assembler) { |
| 195 | Location input = locations->InAt(0); |
| 196 | Location output = locations->Out(); |
| 197 | if (is64bit) { |
| 198 | // Need to use the temporary. |
| 199 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 200 | __ movsd(temp, input.AsFpuRegister<XmmRegister>()); |
| 201 | __ movd(output.AsRegisterPairLow<Register>(), temp); |
| 202 | __ psrlq(temp, Immediate(32)); |
| 203 | __ movd(output.AsRegisterPairHigh<Register>(), temp); |
| 204 | } else { |
| 205 | __ movd(output.AsRegister<Register>(), input.AsFpuRegister<XmmRegister>()); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | static void MoveIntToFP(LocationSummary* locations, bool is64bit, X86Assembler* assembler) { |
| 210 | Location input = locations->InAt(0); |
| 211 | Location output = locations->Out(); |
| 212 | if (is64bit) { |
| 213 | // Need to use the temporary. |
| 214 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 215 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 216 | __ movd(temp1, input.AsRegisterPairLow<Register>()); |
| 217 | __ movd(temp2, input.AsRegisterPairHigh<Register>()); |
| 218 | __ punpckldq(temp1, temp2); |
| 219 | __ movsd(output.AsFpuRegister<XmmRegister>(), temp1); |
| 220 | } else { |
| 221 | __ movd(output.AsFpuRegister<XmmRegister>(), input.AsRegister<Register>()); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | void IntrinsicLocationsBuilderX86::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 226 | CreateFPToIntLocations(allocator_, invoke, /* is64bit= */ true); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 227 | } |
| 228 | void IntrinsicLocationsBuilderX86::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 229 | CreateIntToFPLocations(allocator_, invoke, /* is64bit= */ true); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | void IntrinsicCodeGeneratorX86::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 233 | MoveFPToInt(invoke->GetLocations(), /* is64bit= */ true, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 234 | } |
| 235 | void IntrinsicCodeGeneratorX86::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 236 | MoveIntToFP(invoke->GetLocations(), /* is64bit= */ true, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void IntrinsicLocationsBuilderX86::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 240 | CreateFPToIntLocations(allocator_, invoke, /* is64bit= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 241 | } |
| 242 | void IntrinsicLocationsBuilderX86::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 243 | CreateIntToFPLocations(allocator_, invoke, /* is64bit= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void IntrinsicCodeGeneratorX86::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 247 | MoveFPToInt(invoke->GetLocations(), /* is64bit= */ false, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 248 | } |
| 249 | void IntrinsicCodeGeneratorX86::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 250 | MoveIntToFP(invoke->GetLocations(), /* is64bit= */ false, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 253 | static void CreateIntToIntLocations(ArenaAllocator* allocator, HInvoke* invoke) { |
| 254 | LocationSummary* locations = |
| 255 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 256 | locations->SetInAt(0, Location::RequiresRegister()); |
| 257 | locations->SetOut(Location::SameAsFirstInput()); |
| 258 | } |
| 259 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 260 | static void CreateLongToIntLocations(ArenaAllocator* allocator, HInvoke* invoke) { |
| 261 | LocationSummary* locations = |
| 262 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 263 | locations->SetInAt(0, Location::RequiresRegister()); |
| 264 | locations->SetOut(Location::RequiresRegister()); |
| 265 | } |
| 266 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 267 | static void CreateLongToLongLocations(ArenaAllocator* allocator, HInvoke* invoke) { |
| 268 | LocationSummary* locations = |
| 269 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 270 | locations->SetInAt(0, Location::RequiresRegister()); |
| 271 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 272 | } |
| 273 | |
| 274 | static void GenReverseBytes(LocationSummary* locations, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 275 | DataType::Type size, |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 276 | X86Assembler* assembler) { |
| 277 | Register out = locations->Out().AsRegister<Register>(); |
| 278 | |
| 279 | switch (size) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 280 | case DataType::Type::kInt16: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 281 | // TODO: Can be done with an xchg of 8b registers. This is straight from Quick. |
| 282 | __ bswapl(out); |
| 283 | __ sarl(out, Immediate(16)); |
| 284 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 285 | case DataType::Type::kInt32: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 286 | __ bswapl(out); |
| 287 | break; |
| 288 | default: |
| 289 | LOG(FATAL) << "Unexpected size for reverse-bytes: " << size; |
| 290 | UNREACHABLE(); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | void IntrinsicLocationsBuilderX86::VisitIntegerReverseBytes(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 295 | CreateIntToIntLocations(allocator_, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | void IntrinsicCodeGeneratorX86::VisitIntegerReverseBytes(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 299 | GenReverseBytes(invoke->GetLocations(), DataType::Type::kInt32, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 300 | } |
| 301 | |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 302 | void IntrinsicLocationsBuilderX86::VisitLongReverseBytes(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 303 | CreateLongToLongLocations(allocator_, invoke); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void IntrinsicCodeGeneratorX86::VisitLongReverseBytes(HInvoke* invoke) { |
| 307 | LocationSummary* locations = invoke->GetLocations(); |
| 308 | Location input = locations->InAt(0); |
| 309 | Register input_lo = input.AsRegisterPairLow<Register>(); |
| 310 | Register input_hi = input.AsRegisterPairHigh<Register>(); |
| 311 | Location output = locations->Out(); |
| 312 | Register output_lo = output.AsRegisterPairLow<Register>(); |
| 313 | Register output_hi = output.AsRegisterPairHigh<Register>(); |
| 314 | |
| 315 | X86Assembler* assembler = GetAssembler(); |
| 316 | // Assign the inputs to the outputs, mixing low/high. |
| 317 | __ movl(output_lo, input_hi); |
| 318 | __ movl(output_hi, input_lo); |
| 319 | __ bswapl(output_lo); |
| 320 | __ bswapl(output_hi); |
| 321 | } |
| 322 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 323 | void IntrinsicLocationsBuilderX86::VisitShortReverseBytes(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 324 | CreateIntToIntLocations(allocator_, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | void IntrinsicCodeGeneratorX86::VisitShortReverseBytes(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 328 | GenReverseBytes(invoke->GetLocations(), DataType::Type::kInt16, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 329 | } |
| 330 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 331 | static void CreateFPToFPLocations(ArenaAllocator* allocator, HInvoke* invoke) { |
| 332 | LocationSummary* locations = |
| 333 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 334 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 335 | locations->SetOut(Location::RequiresFpuRegister()); |
| 336 | } |
| 337 | |
| 338 | void IntrinsicLocationsBuilderX86::VisitMathSqrt(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 339 | CreateFPToFPLocations(allocator_, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void IntrinsicCodeGeneratorX86::VisitMathSqrt(HInvoke* invoke) { |
| 343 | LocationSummary* locations = invoke->GetLocations(); |
| 344 | XmmRegister in = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 345 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 346 | |
| 347 | GetAssembler()->sqrtsd(out, in); |
| 348 | } |
| 349 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 350 | static void InvokeOutOfLineIntrinsic(CodeGeneratorX86* codegen, HInvoke* invoke) { |
Roland Levillain | ec525fc | 2015-04-28 15:50:20 +0100 | [diff] [blame] | 351 | MoveArguments(invoke, codegen); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 352 | |
| 353 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 354 | codegen->GenerateStaticOrDirectCall(invoke->AsInvokeStaticOrDirect(), |
| 355 | Location::RegisterLocation(EAX)); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 356 | |
| 357 | // Copy the result back to the expected output. |
| 358 | Location out = invoke->GetLocations()->Out(); |
| 359 | if (out.IsValid()) { |
| 360 | DCHECK(out.IsRegister()); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 361 | codegen->MoveFromReturnRegister(out, invoke->GetType()); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 365 | static void CreateSSE41FPToFPLocations(ArenaAllocator* allocator, |
| 366 | HInvoke* invoke, |
| 367 | CodeGeneratorX86* codegen) { |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 368 | // Do we have instruction support? |
| 369 | if (codegen->GetInstructionSetFeatures().HasSSE4_1()) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 370 | CreateFPToFPLocations(allocator, invoke); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 371 | return; |
| 372 | } |
| 373 | |
| 374 | // We have to fall back to a call to the intrinsic. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 375 | LocationSummary* locations = |
| 376 | new (allocator) LocationSummary(invoke, LocationSummary::kCallOnMainOnly); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 377 | InvokeRuntimeCallingConvention calling_convention; |
| 378 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 379 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
| 380 | // Needs to be EAX for the invoke. |
| 381 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 382 | } |
| 383 | |
| 384 | static void GenSSE41FPToFPIntrinsic(CodeGeneratorX86* codegen, |
| 385 | HInvoke* invoke, |
| 386 | X86Assembler* assembler, |
| 387 | int round_mode) { |
| 388 | LocationSummary* locations = invoke->GetLocations(); |
| 389 | if (locations->WillCall()) { |
| 390 | InvokeOutOfLineIntrinsic(codegen, invoke); |
| 391 | } else { |
| 392 | XmmRegister in = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 393 | XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>(); |
| 394 | __ roundsd(out, in, Immediate(round_mode)); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | void IntrinsicLocationsBuilderX86::VisitMathCeil(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 399 | CreateSSE41FPToFPLocations(allocator_, invoke, codegen_); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | void IntrinsicCodeGeneratorX86::VisitMathCeil(HInvoke* invoke) { |
| 403 | GenSSE41FPToFPIntrinsic(codegen_, invoke, GetAssembler(), 2); |
| 404 | } |
| 405 | |
| 406 | void IntrinsicLocationsBuilderX86::VisitMathFloor(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 407 | CreateSSE41FPToFPLocations(allocator_, invoke, codegen_); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void IntrinsicCodeGeneratorX86::VisitMathFloor(HInvoke* invoke) { |
| 411 | GenSSE41FPToFPIntrinsic(codegen_, invoke, GetAssembler(), 1); |
| 412 | } |
| 413 | |
| 414 | void IntrinsicLocationsBuilderX86::VisitMathRint(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 415 | CreateSSE41FPToFPLocations(allocator_, invoke, codegen_); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | void IntrinsicCodeGeneratorX86::VisitMathRint(HInvoke* invoke) { |
| 419 | GenSSE41FPToFPIntrinsic(codegen_, invoke, GetAssembler(), 0); |
| 420 | } |
| 421 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 422 | void IntrinsicLocationsBuilderX86::VisitMathRoundFloat(HInvoke* invoke) { |
| 423 | // Do we have instruction support? |
| 424 | if (codegen_->GetInstructionSetFeatures().HasSSE4_1()) { |
Aart Bik | 2c9f495 | 2016-08-01 16:52:27 -0700 | [diff] [blame] | 425 | HInvokeStaticOrDirect* static_or_direct = invoke->AsInvokeStaticOrDirect(); |
| 426 | DCHECK(static_or_direct != nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 427 | LocationSummary* locations = |
| 428 | new (allocator_) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 429 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Aart Bik | 2c9f495 | 2016-08-01 16:52:27 -0700 | [diff] [blame] | 430 | if (static_or_direct->HasSpecialInput() && |
| 431 | invoke->InputAt( |
| 432 | static_or_direct->GetSpecialInputIndex())->IsX86ComputeBaseMethodAddress()) { |
| 433 | locations->SetInAt(1, Location::RequiresRegister()); |
| 434 | } |
Nicolas Geoffray | d9b9240 | 2015-04-21 10:02:22 +0100 | [diff] [blame] | 435 | locations->SetOut(Location::RequiresRegister()); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 436 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 437 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | // We have to fall back to a call to the intrinsic. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 442 | LocationSummary* locations = |
| 443 | new (allocator_) LocationSummary(invoke, LocationSummary::kCallOnMainOnly); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 444 | InvokeRuntimeCallingConvention calling_convention; |
| 445 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 446 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 447 | // Needs to be EAX for the invoke. |
| 448 | locations->AddTemp(Location::RegisterLocation(EAX)); |
| 449 | } |
| 450 | |
| 451 | void IntrinsicCodeGeneratorX86::VisitMathRoundFloat(HInvoke* invoke) { |
| 452 | LocationSummary* locations = invoke->GetLocations(); |
Aart Bik | 2c9f495 | 2016-08-01 16:52:27 -0700 | [diff] [blame] | 453 | if (locations->WillCall()) { // TODO: can we reach this? |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 454 | InvokeOutOfLineIntrinsic(codegen_, invoke); |
| 455 | return; |
| 456 | } |
| 457 | |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 458 | XmmRegister in = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
Aart Bik | 2c9f495 | 2016-08-01 16:52:27 -0700 | [diff] [blame] | 459 | XmmRegister t1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 460 | XmmRegister t2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 461 | Register out = locations->Out().AsRegister<Register>(); |
Aart Bik | 2c9f495 | 2016-08-01 16:52:27 -0700 | [diff] [blame] | 462 | NearLabel skip_incr, done; |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 463 | X86Assembler* assembler = GetAssembler(); |
| 464 | |
Aart Bik | 2c9f495 | 2016-08-01 16:52:27 -0700 | [diff] [blame] | 465 | // Since no direct x86 rounding instruction matches the required semantics, |
| 466 | // this intrinsic is implemented as follows: |
| 467 | // result = floor(in); |
| 468 | // if (in - result >= 0.5f) |
| 469 | // result = result + 1.0f; |
| 470 | __ movss(t2, in); |
| 471 | __ roundss(t1, in, Immediate(1)); |
| 472 | __ subss(t2, t1); |
Aart Bik | 0cf8d9c | 2016-08-10 14:05:54 -0700 | [diff] [blame] | 473 | if (locations->GetInputCount() == 2 && locations->InAt(1).IsValid()) { |
| 474 | // Direct constant area available. |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 475 | HX86ComputeBaseMethodAddress* method_address = |
| 476 | invoke->InputAt(1)->AsX86ComputeBaseMethodAddress(); |
Aart Bik | 0cf8d9c | 2016-08-10 14:05:54 -0700 | [diff] [blame] | 477 | Register constant_area = locations->InAt(1).AsRegister<Register>(); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 478 | __ comiss(t2, codegen_->LiteralInt32Address(bit_cast<int32_t, float>(0.5f), |
| 479 | method_address, |
| 480 | constant_area)); |
Aart Bik | 0cf8d9c | 2016-08-10 14:05:54 -0700 | [diff] [blame] | 481 | __ j(kBelow, &skip_incr); |
Nicolas Geoffray | 133719e | 2017-01-22 15:44:39 +0000 | [diff] [blame] | 482 | __ addss(t1, codegen_->LiteralInt32Address(bit_cast<int32_t, float>(1.0f), |
| 483 | method_address, |
| 484 | constant_area)); |
Aart Bik | 0cf8d9c | 2016-08-10 14:05:54 -0700 | [diff] [blame] | 485 | __ Bind(&skip_incr); |
| 486 | } else { |
| 487 | // No constant area: go through stack. |
| 488 | __ pushl(Immediate(bit_cast<int32_t, float>(0.5f))); |
| 489 | __ pushl(Immediate(bit_cast<int32_t, float>(1.0f))); |
| 490 | __ comiss(t2, Address(ESP, 4)); |
| 491 | __ j(kBelow, &skip_incr); |
| 492 | __ addss(t1, Address(ESP, 0)); |
| 493 | __ Bind(&skip_incr); |
| 494 | __ addl(ESP, Immediate(8)); |
| 495 | } |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 496 | |
Aart Bik | 2c9f495 | 2016-08-01 16:52:27 -0700 | [diff] [blame] | 497 | // Final conversion to an integer. Unfortunately this also does not have a |
| 498 | // direct x86 instruction, since NaN should map to 0 and large positive |
| 499 | // values need to be clipped to the extreme value. |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 500 | __ movl(out, Immediate(kPrimIntMax)); |
Aart Bik | 2c9f495 | 2016-08-01 16:52:27 -0700 | [diff] [blame] | 501 | __ cvtsi2ss(t2, out); |
| 502 | __ comiss(t1, t2); |
| 503 | __ j(kAboveEqual, &done); // clipped to max (already in out), does not jump on unordered |
| 504 | __ movl(out, Immediate(0)); // does not change flags |
| 505 | __ j(kUnordered, &done); // NaN mapped to 0 (just moved in out) |
| 506 | __ cvttss2si(out, t1); |
Mark Mendell | fb8d279 | 2015-03-31 22:16:59 -0400 | [diff] [blame] | 507 | __ Bind(&done); |
| 508 | } |
| 509 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 510 | static void CreateFPToFPCallLocations(ArenaAllocator* allocator, HInvoke* invoke) { |
| 511 | LocationSummary* locations = |
| 512 | new (allocator) LocationSummary(invoke, LocationSummary::kCallOnMainOnly, kIntrinsified); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 513 | InvokeRuntimeCallingConvention calling_convention; |
| 514 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 515 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
| 516 | } |
| 517 | |
| 518 | static void GenFPToFPCall(HInvoke* invoke, CodeGeneratorX86* codegen, QuickEntrypointEnum entry) { |
| 519 | LocationSummary* locations = invoke->GetLocations(); |
| 520 | DCHECK(locations->WillCall()); |
| 521 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
| 522 | X86Assembler* assembler = codegen->GetAssembler(); |
| 523 | |
| 524 | // We need some place to pass the parameters. |
| 525 | __ subl(ESP, Immediate(16)); |
| 526 | __ cfi().AdjustCFAOffset(16); |
| 527 | |
| 528 | // Pass the parameters at the bottom of the stack. |
| 529 | __ movsd(Address(ESP, 0), XMM0); |
| 530 | |
| 531 | // If we have a second parameter, pass it next. |
| 532 | if (invoke->GetNumberOfArguments() == 2) { |
| 533 | __ movsd(Address(ESP, 8), XMM1); |
| 534 | } |
| 535 | |
| 536 | // Now do the actual call. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 537 | codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc()); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 538 | |
| 539 | // Extract the return value from the FP stack. |
| 540 | __ fstpl(Address(ESP, 0)); |
| 541 | __ movsd(XMM0, Address(ESP, 0)); |
| 542 | |
| 543 | // And clean up the stack. |
| 544 | __ addl(ESP, Immediate(16)); |
| 545 | __ cfi().AdjustCFAOffset(-16); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 546 | } |
| 547 | |
Shalini Salomi Bodapati | 8943fa1 | 2018-11-21 15:36:00 +0530 | [diff] [blame] | 548 | static void CreateLowestOneBitLocations(ArenaAllocator* allocator, bool is_long, HInvoke* invoke) { |
| 549 | LocationSummary* locations = |
| 550 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
| 551 | if (is_long) { |
| 552 | locations->SetInAt(0, Location::RequiresRegister()); |
| 553 | } else { |
| 554 | locations->SetInAt(0, Location::Any()); |
| 555 | } |
| 556 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 557 | } |
| 558 | |
| 559 | static void GenLowestOneBit(X86Assembler* assembler, |
| 560 | CodeGeneratorX86* codegen, |
| 561 | bool is_long, |
| 562 | HInvoke* invoke) { |
| 563 | LocationSummary* locations = invoke->GetLocations(); |
| 564 | Location src = locations->InAt(0); |
| 565 | Location out_loc = locations->Out(); |
| 566 | |
| 567 | if (invoke->InputAt(0)->IsConstant()) { |
| 568 | // Evaluate this at compile time. |
| 569 | int64_t value = Int64FromConstant(invoke->InputAt(0)->AsConstant()); |
| 570 | if (value == 0) { |
| 571 | if (is_long) { |
| 572 | __ xorl(out_loc.AsRegisterPairLow<Register>(), out_loc.AsRegisterPairLow<Register>()); |
| 573 | __ xorl(out_loc.AsRegisterPairHigh<Register>(), out_loc.AsRegisterPairHigh<Register>()); |
| 574 | } else { |
| 575 | __ xorl(out_loc.AsRegister<Register>(), out_loc.AsRegister<Register>()); |
| 576 | } |
| 577 | return; |
| 578 | } |
| 579 | // Nonzero value. |
| 580 | value = is_long ? CTZ(static_cast<uint64_t>(value)) |
| 581 | : CTZ(static_cast<uint32_t>(value)); |
| 582 | if (is_long) { |
| 583 | if (value >= 32) { |
| 584 | int shift = value-32; |
| 585 | codegen->Load32BitValue(out_loc.AsRegisterPairLow<Register>(), 0); |
| 586 | codegen->Load32BitValue(out_loc.AsRegisterPairHigh<Register>(), 1 << shift); |
| 587 | } else { |
| 588 | codegen->Load32BitValue(out_loc.AsRegisterPairLow<Register>(), 1 << value); |
| 589 | codegen->Load32BitValue(out_loc.AsRegisterPairHigh<Register>(), 0); |
| 590 | } |
| 591 | } else { |
| 592 | codegen->Load32BitValue(out_loc.AsRegister<Register>(), 1 << value); |
| 593 | } |
| 594 | return; |
| 595 | } |
| 596 | // Handle non constant case |
| 597 | if (is_long) { |
| 598 | DCHECK(src.IsRegisterPair()); |
| 599 | Register src_lo = src.AsRegisterPairLow<Register>(); |
| 600 | Register src_hi = src.AsRegisterPairHigh<Register>(); |
| 601 | |
| 602 | Register out_lo = out_loc.AsRegisterPairLow<Register>(); |
| 603 | Register out_hi = out_loc.AsRegisterPairHigh<Register>(); |
| 604 | |
| 605 | __ movl(out_lo, src_lo); |
| 606 | __ movl(out_hi, src_hi); |
| 607 | |
| 608 | __ negl(out_lo); |
| 609 | __ adcl(out_hi, Immediate(0)); |
| 610 | __ negl(out_hi); |
| 611 | |
| 612 | __ andl(out_lo, src_lo); |
| 613 | __ andl(out_hi, src_hi); |
| 614 | } else { |
| 615 | if (codegen->GetInstructionSetFeatures().HasAVX2() && src.IsRegister()) { |
| 616 | Register out = out_loc.AsRegister<Register>(); |
| 617 | __ blsi(out, src.AsRegister<Register>()); |
| 618 | } else { |
| 619 | Register out = out_loc.AsRegister<Register>(); |
| 620 | // Do tmp & -tmp |
| 621 | if (src.IsRegister()) { |
| 622 | __ movl(out, src.AsRegister<Register>()); |
| 623 | } else { |
| 624 | DCHECK(src.IsStackSlot()); |
| 625 | __ movl(out, Address(ESP, src.GetStackIndex())); |
| 626 | } |
| 627 | __ negl(out); |
| 628 | |
| 629 | if (src.IsRegister()) { |
| 630 | __ andl(out, src.AsRegister<Register>()); |
| 631 | } else { |
| 632 | __ andl(out, Address(ESP, src.GetStackIndex())); |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 638 | void IntrinsicLocationsBuilderX86::VisitMathCos(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 639 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | void IntrinsicCodeGeneratorX86::VisitMathCos(HInvoke* invoke) { |
| 643 | GenFPToFPCall(invoke, codegen_, kQuickCos); |
| 644 | } |
| 645 | |
| 646 | void IntrinsicLocationsBuilderX86::VisitMathSin(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 647 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | void IntrinsicCodeGeneratorX86::VisitMathSin(HInvoke* invoke) { |
| 651 | GenFPToFPCall(invoke, codegen_, kQuickSin); |
| 652 | } |
| 653 | |
| 654 | void IntrinsicLocationsBuilderX86::VisitMathAcos(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 655 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | void IntrinsicCodeGeneratorX86::VisitMathAcos(HInvoke* invoke) { |
| 659 | GenFPToFPCall(invoke, codegen_, kQuickAcos); |
| 660 | } |
| 661 | |
| 662 | void IntrinsicLocationsBuilderX86::VisitMathAsin(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 663 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | void IntrinsicCodeGeneratorX86::VisitMathAsin(HInvoke* invoke) { |
| 667 | GenFPToFPCall(invoke, codegen_, kQuickAsin); |
| 668 | } |
| 669 | |
| 670 | void IntrinsicLocationsBuilderX86::VisitMathAtan(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 671 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | void IntrinsicCodeGeneratorX86::VisitMathAtan(HInvoke* invoke) { |
| 675 | GenFPToFPCall(invoke, codegen_, kQuickAtan); |
| 676 | } |
| 677 | |
| 678 | void IntrinsicLocationsBuilderX86::VisitMathCbrt(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 679 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | void IntrinsicCodeGeneratorX86::VisitMathCbrt(HInvoke* invoke) { |
| 683 | GenFPToFPCall(invoke, codegen_, kQuickCbrt); |
| 684 | } |
| 685 | |
| 686 | void IntrinsicLocationsBuilderX86::VisitMathCosh(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 687 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | void IntrinsicCodeGeneratorX86::VisitMathCosh(HInvoke* invoke) { |
| 691 | GenFPToFPCall(invoke, codegen_, kQuickCosh); |
| 692 | } |
| 693 | |
| 694 | void IntrinsicLocationsBuilderX86::VisitMathExp(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 695 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | void IntrinsicCodeGeneratorX86::VisitMathExp(HInvoke* invoke) { |
| 699 | GenFPToFPCall(invoke, codegen_, kQuickExp); |
| 700 | } |
| 701 | |
| 702 | void IntrinsicLocationsBuilderX86::VisitMathExpm1(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 703 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | void IntrinsicCodeGeneratorX86::VisitMathExpm1(HInvoke* invoke) { |
| 707 | GenFPToFPCall(invoke, codegen_, kQuickExpm1); |
| 708 | } |
| 709 | |
| 710 | void IntrinsicLocationsBuilderX86::VisitMathLog(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 711 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | void IntrinsicCodeGeneratorX86::VisitMathLog(HInvoke* invoke) { |
| 715 | GenFPToFPCall(invoke, codegen_, kQuickLog); |
| 716 | } |
| 717 | |
| 718 | void IntrinsicLocationsBuilderX86::VisitMathLog10(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 719 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | void IntrinsicCodeGeneratorX86::VisitMathLog10(HInvoke* invoke) { |
| 723 | GenFPToFPCall(invoke, codegen_, kQuickLog10); |
| 724 | } |
| 725 | |
| 726 | void IntrinsicLocationsBuilderX86::VisitMathSinh(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 727 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | void IntrinsicCodeGeneratorX86::VisitMathSinh(HInvoke* invoke) { |
| 731 | GenFPToFPCall(invoke, codegen_, kQuickSinh); |
| 732 | } |
| 733 | |
| 734 | void IntrinsicLocationsBuilderX86::VisitMathTan(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 735 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | void IntrinsicCodeGeneratorX86::VisitMathTan(HInvoke* invoke) { |
| 739 | GenFPToFPCall(invoke, codegen_, kQuickTan); |
| 740 | } |
| 741 | |
| 742 | void IntrinsicLocationsBuilderX86::VisitMathTanh(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 743 | CreateFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | void IntrinsicCodeGeneratorX86::VisitMathTanh(HInvoke* invoke) { |
| 747 | GenFPToFPCall(invoke, codegen_, kQuickTanh); |
| 748 | } |
| 749 | |
Shalini Salomi Bodapati | 8943fa1 | 2018-11-21 15:36:00 +0530 | [diff] [blame] | 750 | void IntrinsicLocationsBuilderX86::VisitIntegerLowestOneBit(HInvoke* invoke) { |
| 751 | CreateLowestOneBitLocations(allocator_, /*is_long=*/ false, invoke); |
| 752 | } |
| 753 | void IntrinsicCodeGeneratorX86::VisitIntegerLowestOneBit(HInvoke* invoke) { |
| 754 | GenLowestOneBit(GetAssembler(), codegen_, /*is_long=*/ false, invoke); |
| 755 | } |
| 756 | |
| 757 | void IntrinsicLocationsBuilderX86::VisitLongLowestOneBit(HInvoke* invoke) { |
| 758 | CreateLowestOneBitLocations(allocator_, /*is_long=*/ true, invoke); |
| 759 | } |
| 760 | |
| 761 | void IntrinsicCodeGeneratorX86::VisitLongLowestOneBit(HInvoke* invoke) { |
| 762 | GenLowestOneBit(GetAssembler(), codegen_, /*is_long=*/ true, invoke); |
| 763 | } |
| 764 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 765 | static void CreateFPFPToFPCallLocations(ArenaAllocator* allocator, HInvoke* invoke) { |
| 766 | LocationSummary* locations = |
| 767 | new (allocator) LocationSummary(invoke, LocationSummary::kCallOnMainOnly, kIntrinsified); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 768 | InvokeRuntimeCallingConvention calling_convention; |
| 769 | locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0))); |
| 770 | locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1))); |
| 771 | locations->SetOut(Location::FpuRegisterLocation(XMM0)); |
| 772 | } |
| 773 | |
| 774 | void IntrinsicLocationsBuilderX86::VisitMathAtan2(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 775 | CreateFPFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | void IntrinsicCodeGeneratorX86::VisitMathAtan2(HInvoke* invoke) { |
| 779 | GenFPToFPCall(invoke, codegen_, kQuickAtan2); |
| 780 | } |
| 781 | |
Vladimir Marko | 4d17987 | 2018-01-19 14:50:10 +0000 | [diff] [blame] | 782 | void IntrinsicLocationsBuilderX86::VisitMathPow(HInvoke* invoke) { |
| 783 | CreateFPFPToFPCallLocations(allocator_, invoke); |
| 784 | } |
| 785 | |
| 786 | void IntrinsicCodeGeneratorX86::VisitMathPow(HInvoke* invoke) { |
| 787 | GenFPToFPCall(invoke, codegen_, kQuickPow); |
| 788 | } |
| 789 | |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 790 | void IntrinsicLocationsBuilderX86::VisitMathHypot(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 791 | CreateFPFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | void IntrinsicCodeGeneratorX86::VisitMathHypot(HInvoke* invoke) { |
| 795 | GenFPToFPCall(invoke, codegen_, kQuickHypot); |
| 796 | } |
| 797 | |
| 798 | void IntrinsicLocationsBuilderX86::VisitMathNextAfter(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 799 | CreateFPFPToFPCallLocations(allocator_, invoke); |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | void IntrinsicCodeGeneratorX86::VisitMathNextAfter(HInvoke* invoke) { |
| 803 | GenFPToFPCall(invoke, codegen_, kQuickNextAfter); |
| 804 | } |
| 805 | |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 806 | void IntrinsicLocationsBuilderX86::VisitSystemArrayCopyChar(HInvoke* invoke) { |
| 807 | // We need at least two of the positions or length to be an integer constant, |
| 808 | // or else we won't have enough free registers. |
| 809 | HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant(); |
| 810 | HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant(); |
| 811 | HIntConstant* length = invoke->InputAt(4)->AsIntConstant(); |
| 812 | |
| 813 | int num_constants = |
| 814 | ((src_pos != nullptr) ? 1 : 0) |
| 815 | + ((dest_pos != nullptr) ? 1 : 0) |
| 816 | + ((length != nullptr) ? 1 : 0); |
| 817 | |
| 818 | if (num_constants < 2) { |
| 819 | // Not enough free registers. |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | // As long as we are checking, we might as well check to see if the src and dest |
| 824 | // positions are >= 0. |
| 825 | if ((src_pos != nullptr && src_pos->GetValue() < 0) || |
| 826 | (dest_pos != nullptr && dest_pos->GetValue() < 0)) { |
| 827 | // We will have to fail anyways. |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | // And since we are already checking, check the length too. |
| 832 | if (length != nullptr) { |
| 833 | int32_t len = length->GetValue(); |
| 834 | if (len < 0) { |
| 835 | // Just call as normal. |
| 836 | return; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | // Okay, it is safe to generate inline code. |
| 841 | LocationSummary* locations = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 842 | new (allocator_) LocationSummary(invoke, LocationSummary::kCallOnSlowPath, kIntrinsified); |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 843 | // arraycopy(Object src, int srcPos, Object dest, int destPos, int length). |
| 844 | locations->SetInAt(0, Location::RequiresRegister()); |
| 845 | locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1))); |
| 846 | locations->SetInAt(2, Location::RequiresRegister()); |
| 847 | locations->SetInAt(3, Location::RegisterOrConstant(invoke->InputAt(3))); |
| 848 | locations->SetInAt(4, Location::RegisterOrConstant(invoke->InputAt(4))); |
| 849 | |
| 850 | // And we need some temporaries. We will use REP MOVSW, so we need fixed registers. |
| 851 | locations->AddTemp(Location::RegisterLocation(ESI)); |
| 852 | locations->AddTemp(Location::RegisterLocation(EDI)); |
| 853 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 854 | } |
| 855 | |
| 856 | static void CheckPosition(X86Assembler* assembler, |
| 857 | Location pos, |
| 858 | Register input, |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 859 | Location length, |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 860 | SlowPathCode* slow_path, |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 861 | Register temp, |
| 862 | bool length_is_input_length = false) { |
| 863 | // Where is the length in the Array? |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 864 | const uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 865 | |
| 866 | if (pos.IsConstant()) { |
| 867 | int32_t pos_const = pos.GetConstant()->AsIntConstant()->GetValue(); |
| 868 | if (pos_const == 0) { |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 869 | if (!length_is_input_length) { |
| 870 | // Check that length(input) >= length. |
| 871 | if (length.IsConstant()) { |
| 872 | __ cmpl(Address(input, length_offset), |
| 873 | Immediate(length.GetConstant()->AsIntConstant()->GetValue())); |
| 874 | } else { |
| 875 | __ cmpl(Address(input, length_offset), length.AsRegister<Register>()); |
| 876 | } |
| 877 | __ j(kLess, slow_path->GetEntryLabel()); |
| 878 | } |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 879 | } else { |
| 880 | // Check that length(input) >= pos. |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 881 | __ movl(temp, Address(input, length_offset)); |
| 882 | __ subl(temp, Immediate(pos_const)); |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 883 | __ j(kLess, slow_path->GetEntryLabel()); |
| 884 | |
| 885 | // Check that (length(input) - pos) >= length. |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 886 | if (length.IsConstant()) { |
| 887 | __ cmpl(temp, Immediate(length.GetConstant()->AsIntConstant()->GetValue())); |
| 888 | } else { |
| 889 | __ cmpl(temp, length.AsRegister<Register>()); |
| 890 | } |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 891 | __ j(kLess, slow_path->GetEntryLabel()); |
| 892 | } |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 893 | } else if (length_is_input_length) { |
| 894 | // The only way the copy can succeed is if pos is zero. |
| 895 | Register pos_reg = pos.AsRegister<Register>(); |
| 896 | __ testl(pos_reg, pos_reg); |
| 897 | __ j(kNotEqual, slow_path->GetEntryLabel()); |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 898 | } else { |
| 899 | // Check that pos >= 0. |
| 900 | Register pos_reg = pos.AsRegister<Register>(); |
| 901 | __ testl(pos_reg, pos_reg); |
| 902 | __ j(kLess, slow_path->GetEntryLabel()); |
| 903 | |
| 904 | // Check that pos <= length(input). |
| 905 | __ cmpl(Address(input, length_offset), pos_reg); |
| 906 | __ j(kLess, slow_path->GetEntryLabel()); |
| 907 | |
| 908 | // Check that (length(input) - pos) >= length. |
| 909 | __ movl(temp, Address(input, length_offset)); |
| 910 | __ subl(temp, pos_reg); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 911 | if (length.IsConstant()) { |
| 912 | __ cmpl(temp, Immediate(length.GetConstant()->AsIntConstant()->GetValue())); |
| 913 | } else { |
| 914 | __ cmpl(temp, length.AsRegister<Register>()); |
| 915 | } |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 916 | __ j(kLess, slow_path->GetEntryLabel()); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | void IntrinsicCodeGeneratorX86::VisitSystemArrayCopyChar(HInvoke* invoke) { |
| 921 | X86Assembler* assembler = GetAssembler(); |
| 922 | LocationSummary* locations = invoke->GetLocations(); |
| 923 | |
| 924 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 925 | Location srcPos = locations->InAt(1); |
| 926 | Register dest = locations->InAt(2).AsRegister<Register>(); |
| 927 | Location destPos = locations->InAt(3); |
| 928 | Location length = locations->InAt(4); |
| 929 | |
| 930 | // Temporaries that we need for MOVSW. |
| 931 | Register src_base = locations->GetTemp(0).AsRegister<Register>(); |
| 932 | DCHECK_EQ(src_base, ESI); |
| 933 | Register dest_base = locations->GetTemp(1).AsRegister<Register>(); |
| 934 | DCHECK_EQ(dest_base, EDI); |
| 935 | Register count = locations->GetTemp(2).AsRegister<Register>(); |
| 936 | DCHECK_EQ(count, ECX); |
| 937 | |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 938 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) IntrinsicSlowPathX86(invoke); |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 939 | codegen_->AddSlowPath(slow_path); |
| 940 | |
| 941 | // Bail out if the source and destination are the same (to handle overlap). |
| 942 | __ cmpl(src, dest); |
| 943 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 944 | |
| 945 | // Bail out if the source is null. |
| 946 | __ testl(src, src); |
| 947 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 948 | |
| 949 | // Bail out if the destination is null. |
| 950 | __ testl(dest, dest); |
| 951 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 952 | |
| 953 | // If the length is negative, bail out. |
| 954 | // We have already checked in the LocationsBuilder for the constant case. |
| 955 | if (!length.IsConstant()) { |
| 956 | __ cmpl(length.AsRegister<Register>(), length.AsRegister<Register>()); |
| 957 | __ j(kLess, slow_path->GetEntryLabel()); |
| 958 | } |
| 959 | |
| 960 | // We need the count in ECX. |
| 961 | if (length.IsConstant()) { |
| 962 | __ movl(count, Immediate(length.GetConstant()->AsIntConstant()->GetValue())); |
| 963 | } else { |
| 964 | __ movl(count, length.AsRegister<Register>()); |
| 965 | } |
| 966 | |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 967 | // Validity checks: source. Use src_base as a temporary register. |
| 968 | CheckPosition(assembler, srcPos, src, Location::RegisterLocation(count), slow_path, src_base); |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 969 | |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 970 | // Validity checks: dest. Use src_base as a temporary register. |
| 971 | CheckPosition(assembler, destPos, dest, Location::RegisterLocation(count), slow_path, src_base); |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 972 | |
| 973 | // Okay, everything checks out. Finally time to do the copy. |
| 974 | // Check assumption that sizeof(Char) is 2 (used in scaling below). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 975 | const size_t char_size = DataType::Size(DataType::Type::kUint16); |
Mark Mendell | 6bc53a9 | 2015-07-01 14:26:52 -0400 | [diff] [blame] | 976 | DCHECK_EQ(char_size, 2u); |
| 977 | |
| 978 | const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value(); |
| 979 | |
| 980 | if (srcPos.IsConstant()) { |
| 981 | int32_t srcPos_const = srcPos.GetConstant()->AsIntConstant()->GetValue(); |
| 982 | __ leal(src_base, Address(src, char_size * srcPos_const + data_offset)); |
| 983 | } else { |
| 984 | __ leal(src_base, Address(src, srcPos.AsRegister<Register>(), |
| 985 | ScaleFactor::TIMES_2, data_offset)); |
| 986 | } |
| 987 | if (destPos.IsConstant()) { |
| 988 | int32_t destPos_const = destPos.GetConstant()->AsIntConstant()->GetValue(); |
| 989 | |
| 990 | __ leal(dest_base, Address(dest, char_size * destPos_const + data_offset)); |
| 991 | } else { |
| 992 | __ leal(dest_base, Address(dest, destPos.AsRegister<Register>(), |
| 993 | ScaleFactor::TIMES_2, data_offset)); |
| 994 | } |
| 995 | |
| 996 | // Do the move. |
| 997 | __ rep_movsw(); |
| 998 | |
| 999 | __ Bind(slow_path->GetExitLabel()); |
| 1000 | } |
| 1001 | |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1002 | void IntrinsicLocationsBuilderX86::VisitStringCompareTo(HInvoke* invoke) { |
| 1003 | // The inputs plus one temp. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1004 | LocationSummary* locations = new (allocator_) LocationSummary( |
| 1005 | invoke, LocationSummary::kCallOnMainAndSlowPath, kIntrinsified); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1006 | InvokeRuntimeCallingConvention calling_convention; |
| 1007 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1008 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1009 | locations->SetOut(Location::RegisterLocation(EAX)); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | void IntrinsicCodeGeneratorX86::VisitStringCompareTo(HInvoke* invoke) { |
| 1013 | X86Assembler* assembler = GetAssembler(); |
| 1014 | LocationSummary* locations = invoke->GetLocations(); |
| 1015 | |
Nicolas Geoffray | 512e04d | 2015-03-27 17:21:24 +0000 | [diff] [blame] | 1016 | // Note that the null check must have been done earlier. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1017 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1018 | |
| 1019 | Register argument = locations->InAt(1).AsRegister<Register>(); |
| 1020 | __ testl(argument, argument); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1021 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) IntrinsicSlowPathX86(invoke); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1022 | codegen_->AddSlowPath(slow_path); |
| 1023 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1024 | |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1025 | codegen_->InvokeRuntime(kQuickStringCompareTo, invoke, invoke->GetDexPc(), slow_path); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1026 | __ Bind(slow_path->GetExitLabel()); |
| 1027 | } |
| 1028 | |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1029 | void IntrinsicLocationsBuilderX86::VisitStringEquals(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1030 | LocationSummary* locations = |
| 1031 | new (allocator_) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1032 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1033 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1034 | |
| 1035 | // Request temporary registers, ECX and EDI needed for repe_cmpsl instruction. |
| 1036 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 1037 | locations->AddTemp(Location::RegisterLocation(EDI)); |
| 1038 | |
| 1039 | // Set output, ESI needed for repe_cmpsl instruction anyways. |
| 1040 | locations->SetOut(Location::RegisterLocation(ESI), Location::kOutputOverlap); |
| 1041 | } |
| 1042 | |
| 1043 | void IntrinsicCodeGeneratorX86::VisitStringEquals(HInvoke* invoke) { |
| 1044 | X86Assembler* assembler = GetAssembler(); |
| 1045 | LocationSummary* locations = invoke->GetLocations(); |
| 1046 | |
| 1047 | Register str = locations->InAt(0).AsRegister<Register>(); |
| 1048 | Register arg = locations->InAt(1).AsRegister<Register>(); |
| 1049 | Register ecx = locations->GetTemp(0).AsRegister<Register>(); |
| 1050 | Register edi = locations->GetTemp(1).AsRegister<Register>(); |
| 1051 | Register esi = locations->Out().AsRegister<Register>(); |
| 1052 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1053 | NearLabel end, return_true, return_false; |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1054 | |
| 1055 | // Get offsets of count, value, and class fields within a string object. |
| 1056 | const uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 1057 | const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value(); |
| 1058 | const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value(); |
| 1059 | |
| 1060 | // Note that the null check must have been done earlier. |
| 1061 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1062 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1063 | StringEqualsOptimizations optimizations(invoke); |
| 1064 | if (!optimizations.GetArgumentNotNull()) { |
| 1065 | // Check if input is null, return false if it is. |
| 1066 | __ testl(arg, arg); |
| 1067 | __ j(kEqual, &return_false); |
| 1068 | } |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1069 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1070 | if (!optimizations.GetArgumentIsString()) { |
Vladimir Marko | 53b5200 | 2016-05-24 19:30:45 +0100 | [diff] [blame] | 1071 | // Instanceof check for the argument by comparing class fields. |
| 1072 | // All string objects must have the same type since String cannot be subclassed. |
| 1073 | // Receiver must be a string object, so its class field is equal to all strings' class fields. |
| 1074 | // If the argument is a string object, its class field must be equal to receiver's class field. |
Roland Levillain | 1d775d2 | 2018-09-07 13:56:57 +0100 | [diff] [blame] | 1075 | // |
| 1076 | // As the String class is expected to be non-movable, we can read the class |
| 1077 | // field from String.equals' arguments without read barriers. |
| 1078 | AssertNonMovableStringClass(); |
| 1079 | // Also, because we use the loaded class references only to compare them, we |
| 1080 | // don't need to unpoison them. |
| 1081 | // /* HeapReference<Class> */ ecx = str->klass_ |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1082 | __ movl(ecx, Address(str, class_offset)); |
Roland Levillain | 1d775d2 | 2018-09-07 13:56:57 +0100 | [diff] [blame] | 1083 | // if (ecx != /* HeapReference<Class> */ arg->klass_) return false |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1084 | __ cmpl(ecx, Address(arg, class_offset)); |
| 1085 | __ j(kNotEqual, &return_false); |
| 1086 | } |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1087 | |
| 1088 | // Reference equality check, return true if same reference. |
| 1089 | __ cmpl(str, arg); |
| 1090 | __ j(kEqual, &return_true); |
| 1091 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1092 | // Load length and compression flag of receiver string. |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1093 | __ movl(ecx, Address(str, count_offset)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1094 | // Check if lengths and compression flags are equal, return false if they're not. |
| 1095 | // Two identical strings will always have same compression style since |
| 1096 | // compression style is decided on alloc. |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1097 | __ cmpl(ecx, Address(arg, count_offset)); |
| 1098 | __ j(kNotEqual, &return_false); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1099 | // Return true if strings are empty. Even with string compression `count == 0` means empty. |
| 1100 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1101 | "Expecting 0=compressed, 1=uncompressed"); |
| 1102 | __ jecxz(&return_true); |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1103 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1104 | if (mirror::kUseStringCompression) { |
| 1105 | NearLabel string_uncompressed; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1106 | // Extract length and differentiate between both compressed or both uncompressed. |
| 1107 | // Different compression style is cut above. |
| 1108 | __ shrl(ecx, Immediate(1)); |
| 1109 | __ j(kCarrySet, &string_uncompressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1110 | // Divide string length by 2, rounding up, and continue as if uncompressed. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1111 | __ addl(ecx, Immediate(1)); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1112 | __ shrl(ecx, Immediate(1)); |
| 1113 | __ Bind(&string_uncompressed); |
| 1114 | } |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1115 | // Load starting addresses of string values into ESI/EDI as required for repe_cmpsl instruction. |
| 1116 | __ leal(esi, Address(str, value_offset)); |
| 1117 | __ leal(edi, Address(arg, value_offset)); |
| 1118 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1119 | // Divide string length by 2 to compare characters 2 at a time and adjust for lengths not |
| 1120 | // divisible by 2. |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1121 | __ addl(ecx, Immediate(1)); |
| 1122 | __ shrl(ecx, Immediate(1)); |
| 1123 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1124 | // Assertions that must hold in order to compare strings 2 characters (uncompressed) |
| 1125 | // or 4 characters (compressed) at a time. |
Agi Csaki | d7138c8 | 2015-08-13 17:46:44 -0700 | [diff] [blame] | 1126 | DCHECK_ALIGNED(value_offset, 4); |
| 1127 | static_assert(IsAligned<4>(kObjectAlignment), "String of odd length is not zero padded"); |
| 1128 | |
| 1129 | // Loop to compare strings two characters at a time starting at the beginning of the string. |
| 1130 | __ repe_cmpsl(); |
| 1131 | // If strings are not equal, zero flag will be cleared. |
| 1132 | __ j(kNotEqual, &return_false); |
| 1133 | |
| 1134 | // Return true and exit the function. |
| 1135 | // If loop does not result in returning false, we return true. |
| 1136 | __ Bind(&return_true); |
| 1137 | __ movl(esi, Immediate(1)); |
| 1138 | __ jmp(&end); |
| 1139 | |
| 1140 | // Return false and exit the function. |
| 1141 | __ Bind(&return_false); |
| 1142 | __ xorl(esi, esi); |
| 1143 | __ Bind(&end); |
| 1144 | } |
| 1145 | |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1146 | static void CreateStringIndexOfLocations(HInvoke* invoke, |
| 1147 | ArenaAllocator* allocator, |
| 1148 | bool start_at_zero) { |
| 1149 | LocationSummary* locations = new (allocator) LocationSummary(invoke, |
| 1150 | LocationSummary::kCallOnSlowPath, |
| 1151 | kIntrinsified); |
| 1152 | // The data needs to be in EDI for scasw. So request that the string is there, anyways. |
| 1153 | locations->SetInAt(0, Location::RegisterLocation(EDI)); |
| 1154 | // If we look for a constant char, we'll still have to copy it into EAX. So just request the |
| 1155 | // allocator to do that, anyways. We can still do the constant check by checking the parameter |
| 1156 | // of the instruction explicitly. |
| 1157 | // Note: This works as we don't clobber EAX anywhere. |
| 1158 | locations->SetInAt(1, Location::RegisterLocation(EAX)); |
| 1159 | if (!start_at_zero) { |
| 1160 | locations->SetInAt(2, Location::RequiresRegister()); // The starting index. |
| 1161 | } |
| 1162 | // As we clobber EDI during execution anyways, also use it as the output. |
| 1163 | locations->SetOut(Location::SameAsFirstInput()); |
| 1164 | |
| 1165 | // repne scasw uses ECX as the counter. |
| 1166 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 1167 | // Need another temporary to be able to compute the result. |
| 1168 | locations->AddTemp(Location::RequiresRegister()); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1169 | if (mirror::kUseStringCompression) { |
| 1170 | // Need another temporary to be able to save unflagged string length. |
| 1171 | locations->AddTemp(Location::RequiresRegister()); |
| 1172 | } |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | static void GenerateStringIndexOf(HInvoke* invoke, |
| 1176 | X86Assembler* assembler, |
| 1177 | CodeGeneratorX86* codegen, |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1178 | bool start_at_zero) { |
| 1179 | LocationSummary* locations = invoke->GetLocations(); |
| 1180 | |
| 1181 | // Note that the null check must have been done earlier. |
| 1182 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1183 | |
| 1184 | Register string_obj = locations->InAt(0).AsRegister<Register>(); |
| 1185 | Register search_value = locations->InAt(1).AsRegister<Register>(); |
| 1186 | Register counter = locations->GetTemp(0).AsRegister<Register>(); |
| 1187 | Register string_length = locations->GetTemp(1).AsRegister<Register>(); |
| 1188 | Register out = locations->Out().AsRegister<Register>(); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1189 | // Only used when string compression feature is on. |
| 1190 | Register string_length_flagged; |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1191 | |
| 1192 | // Check our assumptions for registers. |
| 1193 | DCHECK_EQ(string_obj, EDI); |
| 1194 | DCHECK_EQ(search_value, EAX); |
| 1195 | DCHECK_EQ(counter, ECX); |
| 1196 | DCHECK_EQ(out, EDI); |
| 1197 | |
| 1198 | // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically, |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1199 | // or directly dispatch for a large constant, or omit slow-path for a small constant or a char. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1200 | SlowPathCode* slow_path = nullptr; |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1201 | HInstruction* code_point = invoke->InputAt(1); |
| 1202 | if (code_point->IsIntConstant()) { |
Vladimir Marko | da05108 | 2016-05-17 16:10:20 +0100 | [diff] [blame] | 1203 | if (static_cast<uint32_t>(code_point->AsIntConstant()->GetValue()) > |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1204 | std::numeric_limits<uint16_t>::max()) { |
| 1205 | // Always needs the slow-path. We could directly dispatch to it, but this case should be |
| 1206 | // rare, so for simplicity just put the full slow-path down and branch unconditionally. |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1207 | slow_path = new (codegen->GetScopedAllocator()) IntrinsicSlowPathX86(invoke); |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1208 | codegen->AddSlowPath(slow_path); |
| 1209 | __ jmp(slow_path->GetEntryLabel()); |
| 1210 | __ Bind(slow_path->GetExitLabel()); |
| 1211 | return; |
| 1212 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1213 | } else if (code_point->GetType() != DataType::Type::kUint16) { |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1214 | __ cmpl(search_value, Immediate(std::numeric_limits<uint16_t>::max())); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1215 | slow_path = new (codegen->GetScopedAllocator()) IntrinsicSlowPathX86(invoke); |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1216 | codegen->AddSlowPath(slow_path); |
| 1217 | __ j(kAbove, slow_path->GetEntryLabel()); |
| 1218 | } |
| 1219 | |
| 1220 | // From here down, we know that we are looking for a char that fits in 16 bits. |
| 1221 | // Location of reference to data array within the String object. |
| 1222 | int32_t value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1223 | // Location of count within the String object. |
| 1224 | int32_t count_offset = mirror::String::CountOffset().Int32Value(); |
| 1225 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1226 | // Load the count field of the string containing the length and compression flag. |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1227 | __ movl(string_length, Address(string_obj, count_offset)); |
| 1228 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1229 | // Do a zero-length check. Even with string compression `count == 0` means empty. |
| 1230 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1231 | "Expecting 0=compressed, 1=uncompressed"); |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1232 | // TODO: Support jecxz. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1233 | NearLabel not_found_label; |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1234 | __ testl(string_length, string_length); |
| 1235 | __ j(kEqual, ¬_found_label); |
| 1236 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1237 | if (mirror::kUseStringCompression) { |
| 1238 | string_length_flagged = locations->GetTemp(2).AsRegister<Register>(); |
| 1239 | __ movl(string_length_flagged, string_length); |
| 1240 | // Extract the length and shift out the least significant bit used as compression flag. |
| 1241 | __ shrl(string_length, Immediate(1)); |
| 1242 | } |
| 1243 | |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1244 | if (start_at_zero) { |
| 1245 | // Number of chars to scan is the same as the string length. |
| 1246 | __ movl(counter, string_length); |
| 1247 | |
| 1248 | // Move to the start of the string. |
| 1249 | __ addl(string_obj, Immediate(value_offset)); |
| 1250 | } else { |
| 1251 | Register start_index = locations->InAt(2).AsRegister<Register>(); |
| 1252 | |
| 1253 | // Do a start_index check. |
| 1254 | __ cmpl(start_index, string_length); |
| 1255 | __ j(kGreaterEqual, ¬_found_label); |
| 1256 | |
| 1257 | // Ensure we have a start index >= 0; |
| 1258 | __ xorl(counter, counter); |
| 1259 | __ cmpl(start_index, Immediate(0)); |
| 1260 | __ cmovl(kGreater, counter, start_index); |
| 1261 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1262 | if (mirror::kUseStringCompression) { |
| 1263 | NearLabel modify_counter, offset_uncompressed_label; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1264 | __ testl(string_length_flagged, Immediate(1)); |
| 1265 | __ j(kNotZero, &offset_uncompressed_label); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1266 | // Move to the start of the string: string_obj + value_offset + start_index. |
| 1267 | __ leal(string_obj, Address(string_obj, counter, ScaleFactor::TIMES_1, value_offset)); |
| 1268 | __ jmp(&modify_counter); |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1269 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1270 | // Move to the start of the string: string_obj + value_offset + 2 * start_index. |
| 1271 | __ Bind(&offset_uncompressed_label); |
| 1272 | __ leal(string_obj, Address(string_obj, counter, ScaleFactor::TIMES_2, value_offset)); |
| 1273 | |
| 1274 | // Now update ecx (the repne scasw work counter). We have string.length - start_index left to |
| 1275 | // compare. |
| 1276 | __ Bind(&modify_counter); |
| 1277 | } else { |
| 1278 | __ leal(string_obj, Address(string_obj, counter, ScaleFactor::TIMES_2, value_offset)); |
| 1279 | } |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1280 | __ negl(counter); |
| 1281 | __ leal(counter, Address(string_length, counter, ScaleFactor::TIMES_1, 0)); |
| 1282 | } |
| 1283 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1284 | if (mirror::kUseStringCompression) { |
| 1285 | NearLabel uncompressed_string_comparison; |
| 1286 | NearLabel comparison_done; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1287 | __ testl(string_length_flagged, Immediate(1)); |
| 1288 | __ j(kNotZero, &uncompressed_string_comparison); |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1289 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1290 | // Check if EAX (search_value) is ASCII. |
| 1291 | __ cmpl(search_value, Immediate(127)); |
| 1292 | __ j(kGreater, ¬_found_label); |
| 1293 | // Comparing byte-per-byte. |
| 1294 | __ repne_scasb(); |
| 1295 | __ jmp(&comparison_done); |
| 1296 | |
| 1297 | // Everything is set up for repne scasw: |
| 1298 | // * Comparison address in EDI. |
| 1299 | // * Counter in ECX. |
| 1300 | __ Bind(&uncompressed_string_comparison); |
| 1301 | __ repne_scasw(); |
| 1302 | __ Bind(&comparison_done); |
| 1303 | } else { |
| 1304 | __ repne_scasw(); |
| 1305 | } |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1306 | // Did we find a match? |
| 1307 | __ j(kNotEqual, ¬_found_label); |
| 1308 | |
| 1309 | // Yes, we matched. Compute the index of the result. |
| 1310 | __ subl(string_length, counter); |
| 1311 | __ leal(out, Address(string_length, -1)); |
| 1312 | |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 1313 | NearLabel done; |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1314 | __ jmp(&done); |
| 1315 | |
| 1316 | // Failed to match; return -1. |
| 1317 | __ Bind(¬_found_label); |
| 1318 | __ movl(out, Immediate(-1)); |
| 1319 | |
| 1320 | // And join up at the end. |
| 1321 | __ Bind(&done); |
| 1322 | if (slow_path != nullptr) { |
| 1323 | __ Bind(slow_path->GetExitLabel()); |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | void IntrinsicLocationsBuilderX86::VisitStringIndexOf(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1328 | CreateStringIndexOfLocations(invoke, allocator_, /* start_at_zero= */ true); |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | void IntrinsicCodeGeneratorX86::VisitStringIndexOf(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1332 | GenerateStringIndexOf(invoke, GetAssembler(), codegen_, /* start_at_zero= */ true); |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | void IntrinsicLocationsBuilderX86::VisitStringIndexOfAfter(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1336 | CreateStringIndexOfLocations(invoke, allocator_, /* start_at_zero= */ false); |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | void IntrinsicCodeGeneratorX86::VisitStringIndexOfAfter(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1340 | GenerateStringIndexOf(invoke, GetAssembler(), codegen_, /* start_at_zero= */ false); |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 1341 | } |
| 1342 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1343 | void IntrinsicLocationsBuilderX86::VisitStringNewStringFromBytes(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1344 | LocationSummary* locations = new (allocator_) LocationSummary( |
| 1345 | invoke, LocationSummary::kCallOnMainAndSlowPath, kIntrinsified); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1346 | InvokeRuntimeCallingConvention calling_convention; |
| 1347 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1348 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1349 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1350 | locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 1351 | locations->SetOut(Location::RegisterLocation(EAX)); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | void IntrinsicCodeGeneratorX86::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1355 | X86Assembler* assembler = GetAssembler(); |
| 1356 | LocationSummary* locations = invoke->GetLocations(); |
| 1357 | |
| 1358 | Register byte_array = locations->InAt(0).AsRegister<Register>(); |
| 1359 | __ testl(byte_array, byte_array); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1360 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) IntrinsicSlowPathX86(invoke); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1361 | codegen_->AddSlowPath(slow_path); |
| 1362 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1363 | |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1364 | codegen_->InvokeRuntime(kQuickAllocStringFromBytes, invoke, invoke->GetDexPc()); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1365 | CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1366 | __ Bind(slow_path->GetExitLabel()); |
| 1367 | } |
| 1368 | |
| 1369 | void IntrinsicLocationsBuilderX86::VisitStringNewStringFromChars(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1370 | LocationSummary* locations = |
| 1371 | new (allocator_) LocationSummary(invoke, LocationSummary::kCallOnMainOnly, kIntrinsified); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1372 | InvokeRuntimeCallingConvention calling_convention; |
| 1373 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1374 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1375 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1376 | locations->SetOut(Location::RegisterLocation(EAX)); |
| 1377 | } |
| 1378 | |
| 1379 | void IntrinsicCodeGeneratorX86::VisitStringNewStringFromChars(HInvoke* invoke) { |
Roland Levillain | cc3839c | 2016-02-29 16:23:48 +0000 | [diff] [blame] | 1380 | // No need to emit code checking whether `locations->InAt(2)` is a null |
| 1381 | // pointer, as callers of the native method |
| 1382 | // |
| 1383 | // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data) |
| 1384 | // |
| 1385 | // all include a null check on `data` before calling that method. |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1386 | codegen_->InvokeRuntime(kQuickAllocStringFromChars, invoke, invoke->GetDexPc()); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1387 | CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | void IntrinsicLocationsBuilderX86::VisitStringNewStringFromString(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1391 | LocationSummary* locations = new (allocator_) LocationSummary( |
| 1392 | invoke, LocationSummary::kCallOnMainAndSlowPath, kIntrinsified); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1393 | InvokeRuntimeCallingConvention calling_convention; |
| 1394 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1395 | locations->SetOut(Location::RegisterLocation(EAX)); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | void IntrinsicCodeGeneratorX86::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1399 | X86Assembler* assembler = GetAssembler(); |
| 1400 | LocationSummary* locations = invoke->GetLocations(); |
| 1401 | |
| 1402 | Register string_to_copy = locations->InAt(0).AsRegister<Register>(); |
| 1403 | __ testl(string_to_copy, string_to_copy); |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 1404 | SlowPathCode* slow_path = new (codegen_->GetScopedAllocator()) IntrinsicSlowPathX86(invoke); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1405 | codegen_->AddSlowPath(slow_path); |
| 1406 | __ j(kEqual, slow_path->GetEntryLabel()); |
| 1407 | |
Serban Constantinescu | ba45db0 | 2016-07-12 22:53:02 +0100 | [diff] [blame] | 1408 | codegen_->InvokeRuntime(kQuickAllocStringFromString, invoke, invoke->GetDexPc()); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1409 | CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1410 | __ Bind(slow_path->GetExitLabel()); |
| 1411 | } |
| 1412 | |
Mark Mendell | 8f8926a | 2015-08-17 11:39:06 -0400 | [diff] [blame] | 1413 | void IntrinsicLocationsBuilderX86::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
| 1414 | // public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1415 | LocationSummary* locations = |
| 1416 | new (allocator_) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 8f8926a | 2015-08-17 11:39:06 -0400 | [diff] [blame] | 1417 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1418 | locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1))); |
| 1419 | // Place srcEnd in ECX to save a move below. |
| 1420 | locations->SetInAt(2, Location::RegisterLocation(ECX)); |
| 1421 | locations->SetInAt(3, Location::RequiresRegister()); |
| 1422 | locations->SetInAt(4, Location::RequiresRegister()); |
| 1423 | |
| 1424 | // And we need some temporaries. We will use REP MOVSW, so we need fixed registers. |
| 1425 | // We don't have enough registers to also grab ECX, so handle below. |
| 1426 | locations->AddTemp(Location::RegisterLocation(ESI)); |
| 1427 | locations->AddTemp(Location::RegisterLocation(EDI)); |
| 1428 | } |
| 1429 | |
| 1430 | void IntrinsicCodeGeneratorX86::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
| 1431 | X86Assembler* assembler = GetAssembler(); |
| 1432 | LocationSummary* locations = invoke->GetLocations(); |
| 1433 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1434 | size_t char_component_size = DataType::Size(DataType::Type::kUint16); |
Mark Mendell | 8f8926a | 2015-08-17 11:39:06 -0400 | [diff] [blame] | 1435 | // Location of data in char array buffer. |
| 1436 | const uint32_t data_offset = mirror::Array::DataOffset(char_component_size).Uint32Value(); |
| 1437 | // Location of char array data in string. |
| 1438 | const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value(); |
| 1439 | |
| 1440 | // public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin); |
| 1441 | Register obj = locations->InAt(0).AsRegister<Register>(); |
| 1442 | Location srcBegin = locations->InAt(1); |
| 1443 | int srcBegin_value = |
| 1444 | srcBegin.IsConstant() ? srcBegin.GetConstant()->AsIntConstant()->GetValue() : 0; |
| 1445 | Register srcEnd = locations->InAt(2).AsRegister<Register>(); |
| 1446 | Register dst = locations->InAt(3).AsRegister<Register>(); |
| 1447 | Register dstBegin = locations->InAt(4).AsRegister<Register>(); |
| 1448 | |
| 1449 | // Check assumption that sizeof(Char) is 2 (used in scaling below). |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1450 | const size_t char_size = DataType::Size(DataType::Type::kUint16); |
Mark Mendell | 8f8926a | 2015-08-17 11:39:06 -0400 | [diff] [blame] | 1451 | DCHECK_EQ(char_size, 2u); |
| 1452 | |
Mark Mendell | 8f8926a | 2015-08-17 11:39:06 -0400 | [diff] [blame] | 1453 | // Compute the number of chars (words) to move. |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1454 | // Save ECX, since we don't know if it will be used later. |
Mark Mendell | 8f8926a | 2015-08-17 11:39:06 -0400 | [diff] [blame] | 1455 | __ pushl(ECX); |
| 1456 | int stack_adjust = kX86WordSize; |
| 1457 | __ cfi().AdjustCFAOffset(stack_adjust); |
| 1458 | DCHECK_EQ(srcEnd, ECX); |
| 1459 | if (srcBegin.IsConstant()) { |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1460 | __ subl(ECX, Immediate(srcBegin_value)); |
Mark Mendell | 8f8926a | 2015-08-17 11:39:06 -0400 | [diff] [blame] | 1461 | } else { |
| 1462 | DCHECK(srcBegin.IsRegister()); |
| 1463 | __ subl(ECX, srcBegin.AsRegister<Register>()); |
| 1464 | } |
| 1465 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1466 | NearLabel done; |
| 1467 | if (mirror::kUseStringCompression) { |
| 1468 | // Location of count in string |
| 1469 | const uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1470 | const size_t c_char_size = DataType::Size(DataType::Type::kInt8); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1471 | DCHECK_EQ(c_char_size, 1u); |
| 1472 | __ pushl(EAX); |
| 1473 | __ cfi().AdjustCFAOffset(stack_adjust); |
| 1474 | |
| 1475 | NearLabel copy_loop, copy_uncompressed; |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1476 | __ testl(Address(obj, count_offset), Immediate(1)); |
| 1477 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1478 | "Expecting 0=compressed, 1=uncompressed"); |
| 1479 | __ j(kNotZero, ©_uncompressed); |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1480 | // Compute the address of the source string by adding the number of chars from |
| 1481 | // the source beginning to the value offset of a string. |
| 1482 | __ leal(ESI, CodeGeneratorX86::ArrayAddress(obj, srcBegin, TIMES_1, value_offset)); |
| 1483 | |
| 1484 | // Start the loop to copy String's value to Array of Char. |
| 1485 | __ leal(EDI, Address(dst, dstBegin, ScaleFactor::TIMES_2, data_offset)); |
| 1486 | __ Bind(©_loop); |
| 1487 | __ jecxz(&done); |
| 1488 | // Use EAX temporary (convert byte from ESI to word). |
| 1489 | // TODO: Use LODSB/STOSW (not supported by X86Assembler) with AH initialized to 0. |
| 1490 | __ movzxb(EAX, Address(ESI, 0)); |
| 1491 | __ movw(Address(EDI, 0), EAX); |
| 1492 | __ leal(EDI, Address(EDI, char_size)); |
| 1493 | __ leal(ESI, Address(ESI, c_char_size)); |
| 1494 | // TODO: Add support for LOOP to X86Assembler. |
| 1495 | __ subl(ECX, Immediate(1)); |
| 1496 | __ jmp(©_loop); |
| 1497 | __ Bind(©_uncompressed); |
| 1498 | } |
| 1499 | |
| 1500 | // Do the copy for uncompressed string. |
| 1501 | // Compute the address of the destination buffer. |
| 1502 | __ leal(EDI, Address(dst, dstBegin, ScaleFactor::TIMES_2, data_offset)); |
| 1503 | __ leal(ESI, CodeGeneratorX86::ArrayAddress(obj, srcBegin, TIMES_2, value_offset)); |
Mark Mendell | 8f8926a | 2015-08-17 11:39:06 -0400 | [diff] [blame] | 1504 | __ rep_movsw(); |
| 1505 | |
jessicahandojo | 4877b79 | 2016-09-08 19:49:13 -0700 | [diff] [blame] | 1506 | __ Bind(&done); |
| 1507 | if (mirror::kUseStringCompression) { |
| 1508 | // Restore EAX. |
| 1509 | __ popl(EAX); |
| 1510 | __ cfi().AdjustCFAOffset(-stack_adjust); |
| 1511 | } |
| 1512 | // Restore ECX. |
Mark Mendell | 8f8926a | 2015-08-17 11:39:06 -0400 | [diff] [blame] | 1513 | __ popl(ECX); |
| 1514 | __ cfi().AdjustCFAOffset(-stack_adjust); |
| 1515 | } |
| 1516 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1517 | static void GenPeek(LocationSummary* locations, DataType::Type size, X86Assembler* assembler) { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1518 | Register address = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1519 | Location out_loc = locations->Out(); |
| 1520 | // x86 allows unaligned access. We do not have to check the input or use specific instructions |
| 1521 | // to avoid a SIGBUS. |
| 1522 | switch (size) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1523 | case DataType::Type::kInt8: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1524 | __ movsxb(out_loc.AsRegister<Register>(), Address(address, 0)); |
| 1525 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1526 | case DataType::Type::kInt16: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1527 | __ movsxw(out_loc.AsRegister<Register>(), Address(address, 0)); |
| 1528 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1529 | case DataType::Type::kInt32: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1530 | __ movl(out_loc.AsRegister<Register>(), Address(address, 0)); |
| 1531 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1532 | case DataType::Type::kInt64: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1533 | __ movl(out_loc.AsRegisterPairLow<Register>(), Address(address, 0)); |
| 1534 | __ movl(out_loc.AsRegisterPairHigh<Register>(), Address(address, 4)); |
| 1535 | break; |
| 1536 | default: |
| 1537 | LOG(FATAL) << "Type not recognized for peek: " << size; |
| 1538 | UNREACHABLE(); |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | void IntrinsicLocationsBuilderX86::VisitMemoryPeekByte(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1543 | CreateLongToIntLocations(allocator_, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | void IntrinsicCodeGeneratorX86::VisitMemoryPeekByte(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1547 | GenPeek(invoke->GetLocations(), DataType::Type::kInt8, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | void IntrinsicLocationsBuilderX86::VisitMemoryPeekIntNative(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1551 | CreateLongToIntLocations(allocator_, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | void IntrinsicCodeGeneratorX86::VisitMemoryPeekIntNative(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1555 | GenPeek(invoke->GetLocations(), DataType::Type::kInt32, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | void IntrinsicLocationsBuilderX86::VisitMemoryPeekLongNative(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1559 | CreateLongToLongLocations(allocator_, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | void IntrinsicCodeGeneratorX86::VisitMemoryPeekLongNative(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1563 | GenPeek(invoke->GetLocations(), DataType::Type::kInt64, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | void IntrinsicLocationsBuilderX86::VisitMemoryPeekShortNative(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1567 | CreateLongToIntLocations(allocator_, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | void IntrinsicCodeGeneratorX86::VisitMemoryPeekShortNative(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1571 | GenPeek(invoke->GetLocations(), DataType::Type::kInt16, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1572 | } |
| 1573 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1574 | static void CreateLongIntToVoidLocations(ArenaAllocator* allocator, |
| 1575 | DataType::Type size, |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1576 | HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1577 | LocationSummary* locations = |
| 1578 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1579 | locations->SetInAt(0, Location::RequiresRegister()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1580 | HInstruction* value = invoke->InputAt(1); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1581 | if (size == DataType::Type::kInt8) { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1582 | locations->SetInAt(1, Location::ByteRegisterOrConstant(EDX, value)); |
| 1583 | } else { |
| 1584 | locations->SetInAt(1, Location::RegisterOrConstant(value)); |
| 1585 | } |
| 1586 | } |
| 1587 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1588 | static void GenPoke(LocationSummary* locations, DataType::Type size, X86Assembler* assembler) { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1589 | Register address = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1590 | Location value_loc = locations->InAt(1); |
| 1591 | // x86 allows unaligned access. We do not have to check the input or use specific instructions |
| 1592 | // to avoid a SIGBUS. |
| 1593 | switch (size) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1594 | case DataType::Type::kInt8: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1595 | if (value_loc.IsConstant()) { |
| 1596 | __ movb(Address(address, 0), |
| 1597 | Immediate(value_loc.GetConstant()->AsIntConstant()->GetValue())); |
| 1598 | } else { |
| 1599 | __ movb(Address(address, 0), value_loc.AsRegister<ByteRegister>()); |
| 1600 | } |
| 1601 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1602 | case DataType::Type::kInt16: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1603 | if (value_loc.IsConstant()) { |
| 1604 | __ movw(Address(address, 0), |
| 1605 | Immediate(value_loc.GetConstant()->AsIntConstant()->GetValue())); |
| 1606 | } else { |
| 1607 | __ movw(Address(address, 0), value_loc.AsRegister<Register>()); |
| 1608 | } |
| 1609 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1610 | case DataType::Type::kInt32: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1611 | if (value_loc.IsConstant()) { |
| 1612 | __ movl(Address(address, 0), |
| 1613 | Immediate(value_loc.GetConstant()->AsIntConstant()->GetValue())); |
| 1614 | } else { |
| 1615 | __ movl(Address(address, 0), value_loc.AsRegister<Register>()); |
| 1616 | } |
| 1617 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1618 | case DataType::Type::kInt64: |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1619 | if (value_loc.IsConstant()) { |
| 1620 | int64_t value = value_loc.GetConstant()->AsLongConstant()->GetValue(); |
| 1621 | __ movl(Address(address, 0), Immediate(Low32Bits(value))); |
| 1622 | __ movl(Address(address, 4), Immediate(High32Bits(value))); |
| 1623 | } else { |
| 1624 | __ movl(Address(address, 0), value_loc.AsRegisterPairLow<Register>()); |
| 1625 | __ movl(Address(address, 4), value_loc.AsRegisterPairHigh<Register>()); |
| 1626 | } |
| 1627 | break; |
| 1628 | default: |
| 1629 | LOG(FATAL) << "Type not recognized for poke: " << size; |
| 1630 | UNREACHABLE(); |
| 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | void IntrinsicLocationsBuilderX86::VisitMemoryPokeByte(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1635 | CreateLongIntToVoidLocations(allocator_, DataType::Type::kInt8, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | void IntrinsicCodeGeneratorX86::VisitMemoryPokeByte(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1639 | GenPoke(invoke->GetLocations(), DataType::Type::kInt8, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | void IntrinsicLocationsBuilderX86::VisitMemoryPokeIntNative(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1643 | CreateLongIntToVoidLocations(allocator_, DataType::Type::kInt32, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | void IntrinsicCodeGeneratorX86::VisitMemoryPokeIntNative(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1647 | GenPoke(invoke->GetLocations(), DataType::Type::kInt32, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | void IntrinsicLocationsBuilderX86::VisitMemoryPokeLongNative(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1651 | CreateLongIntToVoidLocations(allocator_, DataType::Type::kInt64, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | void IntrinsicCodeGeneratorX86::VisitMemoryPokeLongNative(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1655 | GenPoke(invoke->GetLocations(), DataType::Type::kInt64, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | void IntrinsicLocationsBuilderX86::VisitMemoryPokeShortNative(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1659 | CreateLongIntToVoidLocations(allocator_, DataType::Type::kInt16, invoke); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | void IntrinsicCodeGeneratorX86::VisitMemoryPokeShortNative(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1663 | GenPoke(invoke->GetLocations(), DataType::Type::kInt16, GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | void IntrinsicLocationsBuilderX86::VisitThreadCurrentThread(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1667 | LocationSummary* locations = |
| 1668 | new (allocator_) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1669 | locations->SetOut(Location::RequiresRegister()); |
| 1670 | } |
| 1671 | |
| 1672 | void IntrinsicCodeGeneratorX86::VisitThreadCurrentThread(HInvoke* invoke) { |
| 1673 | Register out = invoke->GetLocations()->Out().AsRegister<Register>(); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1674 | GetAssembler()->fs()->movl(out, Address::Absolute(Thread::PeerOffset<kX86PointerSize>())); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1675 | } |
| 1676 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1677 | static void GenUnsafeGet(HInvoke* invoke, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1678 | DataType::Type type, |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1679 | bool is_volatile, |
| 1680 | CodeGeneratorX86* codegen) { |
| 1681 | X86Assembler* assembler = down_cast<X86Assembler*>(codegen->GetAssembler()); |
| 1682 | LocationSummary* locations = invoke->GetLocations(); |
| 1683 | Location base_loc = locations->InAt(1); |
| 1684 | Register base = base_loc.AsRegister<Register>(); |
| 1685 | Location offset_loc = locations->InAt(2); |
| 1686 | Register offset = offset_loc.AsRegisterPairLow<Register>(); |
| 1687 | Location output_loc = locations->Out(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1688 | |
| 1689 | switch (type) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1690 | case DataType::Type::kInt32: { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1691 | Register output = output_loc.AsRegister<Register>(); |
| 1692 | __ movl(output, Address(base, offset, ScaleFactor::TIMES_1, 0)); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1693 | break; |
| 1694 | } |
| 1695 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1696 | case DataType::Type::kReference: { |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1697 | Register output = output_loc.AsRegister<Register>(); |
| 1698 | if (kEmitCompilerReadBarrier) { |
| 1699 | if (kUseBakerReadBarrier) { |
Sang, Chunlei | 0fcd2b8 | 2016-04-05 17:12:59 +0800 | [diff] [blame] | 1700 | Address src(base, offset, ScaleFactor::TIMES_1, 0); |
| 1701 | codegen->GenerateReferenceLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1702 | invoke, output_loc, base, src, /* needs_null_check= */ false); |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1703 | } else { |
| 1704 | __ movl(output, Address(base, offset, ScaleFactor::TIMES_1, 0)); |
| 1705 | codegen->GenerateReadBarrierSlow( |
| 1706 | invoke, output_loc, output_loc, base_loc, 0U, offset_loc); |
| 1707 | } |
| 1708 | } else { |
| 1709 | __ movl(output, Address(base, offset, ScaleFactor::TIMES_1, 0)); |
| 1710 | __ MaybeUnpoisonHeapReference(output); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1711 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1712 | break; |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1713 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1714 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1715 | case DataType::Type::kInt64: { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1716 | Register output_lo = output_loc.AsRegisterPairLow<Register>(); |
| 1717 | Register output_hi = output_loc.AsRegisterPairHigh<Register>(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1718 | if (is_volatile) { |
| 1719 | // Need to use a XMM to read atomically. |
| 1720 | XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1721 | __ movsd(temp, Address(base, offset, ScaleFactor::TIMES_1, 0)); |
| 1722 | __ movd(output_lo, temp); |
| 1723 | __ psrlq(temp, Immediate(32)); |
| 1724 | __ movd(output_hi, temp); |
| 1725 | } else { |
| 1726 | __ movl(output_lo, Address(base, offset, ScaleFactor::TIMES_1, 0)); |
| 1727 | __ movl(output_hi, Address(base, offset, ScaleFactor::TIMES_1, 4)); |
| 1728 | } |
| 1729 | } |
| 1730 | break; |
| 1731 | |
| 1732 | default: |
| 1733 | LOG(FATAL) << "Unsupported op size " << type; |
| 1734 | UNREACHABLE(); |
| 1735 | } |
| 1736 | } |
| 1737 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1738 | static void CreateIntIntIntToIntLocations(ArenaAllocator* allocator, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1739 | HInvoke* invoke, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1740 | DataType::Type type, |
Roland Levillain | 7c1559a | 2015-12-15 10:55:36 +0000 | [diff] [blame] | 1741 | bool is_volatile) { |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1742 | bool can_call = kEmitCompilerReadBarrier && |
| 1743 | (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject || |
| 1744 | invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1745 | LocationSummary* locations = |
| 1746 | new (allocator) LocationSummary(invoke, |
| 1747 | can_call |
| 1748 | ? LocationSummary::kCallOnSlowPath |
| 1749 | : LocationSummary::kNoCall, |
| 1750 | kIntrinsified); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1751 | if (can_call && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 1752 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 1753 | } |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1754 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 1755 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1756 | locations->SetInAt(2, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1757 | if (type == DataType::Type::kInt64) { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1758 | if (is_volatile) { |
| 1759 | // Need to use XMM to read volatile. |
| 1760 | locations->AddTemp(Location::RequiresFpuRegister()); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1761 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1762 | } else { |
| 1763 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1764 | } |
| 1765 | } else { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1766 | locations->SetOut(Location::RequiresRegister(), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1767 | (can_call ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1768 | } |
| 1769 | } |
| 1770 | |
| 1771 | void IntrinsicLocationsBuilderX86::VisitUnsafeGet(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1772 | CreateIntIntIntToIntLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1773 | allocator_, invoke, DataType::Type::kInt32, /* is_volatile= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1774 | } |
| 1775 | void IntrinsicLocationsBuilderX86::VisitUnsafeGetVolatile(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1776 | CreateIntIntIntToIntLocations(allocator_, invoke, DataType::Type::kInt32, /* is_volatile= */ true); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1777 | } |
| 1778 | void IntrinsicLocationsBuilderX86::VisitUnsafeGetLong(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1779 | CreateIntIntIntToIntLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1780 | allocator_, invoke, DataType::Type::kInt64, /* is_volatile= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1781 | } |
| 1782 | void IntrinsicLocationsBuilderX86::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1783 | CreateIntIntIntToIntLocations(allocator_, invoke, DataType::Type::kInt64, /* is_volatile= */ true); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1784 | } |
| 1785 | void IntrinsicLocationsBuilderX86::VisitUnsafeGetObject(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1786 | CreateIntIntIntToIntLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1787 | allocator_, invoke, DataType::Type::kReference, /* is_volatile= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1788 | } |
| 1789 | void IntrinsicLocationsBuilderX86::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1790 | CreateIntIntIntToIntLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1791 | allocator_, invoke, DataType::Type::kReference, /* is_volatile= */ true); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | |
| 1795 | void IntrinsicCodeGeneratorX86::VisitUnsafeGet(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1796 | GenUnsafeGet(invoke, DataType::Type::kInt32, /* is_volatile= */ false, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1797 | } |
| 1798 | void IntrinsicCodeGeneratorX86::VisitUnsafeGetVolatile(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1799 | GenUnsafeGet(invoke, DataType::Type::kInt32, /* is_volatile= */ true, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1800 | } |
| 1801 | void IntrinsicCodeGeneratorX86::VisitUnsafeGetLong(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1802 | GenUnsafeGet(invoke, DataType::Type::kInt64, /* is_volatile= */ false, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1803 | } |
| 1804 | void IntrinsicCodeGeneratorX86::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1805 | GenUnsafeGet(invoke, DataType::Type::kInt64, /* is_volatile= */ true, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1806 | } |
| 1807 | void IntrinsicCodeGeneratorX86::VisitUnsafeGetObject(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1808 | GenUnsafeGet(invoke, DataType::Type::kReference, /* is_volatile= */ false, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1809 | } |
| 1810 | void IntrinsicCodeGeneratorX86::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1811 | GenUnsafeGet(invoke, DataType::Type::kReference, /* is_volatile= */ true, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1815 | static void CreateIntIntIntIntToVoidPlusTempsLocations(ArenaAllocator* allocator, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1816 | DataType::Type type, |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1817 | HInvoke* invoke, |
| 1818 | bool is_volatile) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1819 | LocationSummary* locations = |
| 1820 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1821 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 1822 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1823 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1824 | locations->SetInAt(3, Location::RequiresRegister()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1825 | if (type == DataType::Type::kReference) { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1826 | // Need temp registers for card-marking. |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1827 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1828 | // Ensure the value is in a byte register. |
| 1829 | locations->AddTemp(Location::RegisterLocation(ECX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1830 | } else if (type == DataType::Type::kInt64 && is_volatile) { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1831 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1832 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | void IntrinsicLocationsBuilderX86::VisitUnsafePut(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1837 | CreateIntIntIntIntToVoidPlusTempsLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1838 | allocator_, DataType::Type::kInt32, invoke, /* is_volatile= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1839 | } |
| 1840 | void IntrinsicLocationsBuilderX86::VisitUnsafePutOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1841 | CreateIntIntIntIntToVoidPlusTempsLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1842 | allocator_, DataType::Type::kInt32, invoke, /* is_volatile= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1843 | } |
| 1844 | void IntrinsicLocationsBuilderX86::VisitUnsafePutVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1845 | CreateIntIntIntIntToVoidPlusTempsLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1846 | allocator_, DataType::Type::kInt32, invoke, /* is_volatile= */ true); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1847 | } |
| 1848 | void IntrinsicLocationsBuilderX86::VisitUnsafePutObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1849 | CreateIntIntIntIntToVoidPlusTempsLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1850 | allocator_, DataType::Type::kReference, invoke, /* is_volatile= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1851 | } |
| 1852 | void IntrinsicLocationsBuilderX86::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1853 | CreateIntIntIntIntToVoidPlusTempsLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1854 | allocator_, DataType::Type::kReference, invoke, /* is_volatile= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1855 | } |
| 1856 | void IntrinsicLocationsBuilderX86::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1857 | CreateIntIntIntIntToVoidPlusTempsLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1858 | allocator_, DataType::Type::kReference, invoke, /* is_volatile= */ true); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1859 | } |
| 1860 | void IntrinsicLocationsBuilderX86::VisitUnsafePutLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1861 | CreateIntIntIntIntToVoidPlusTempsLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1862 | allocator_, DataType::Type::kInt64, invoke, /* is_volatile= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1863 | } |
| 1864 | void IntrinsicLocationsBuilderX86::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1865 | CreateIntIntIntIntToVoidPlusTempsLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1866 | allocator_, DataType::Type::kInt64, invoke, /* is_volatile= */ false); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1867 | } |
| 1868 | void IntrinsicLocationsBuilderX86::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1869 | CreateIntIntIntIntToVoidPlusTempsLocations( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1870 | allocator_, DataType::Type::kInt64, invoke, /* is_volatile= */ true); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | // We don't care for ordered: it requires an AnyStore barrier, which is already given by the x86 |
| 1874 | // memory model. |
| 1875 | static void GenUnsafePut(LocationSummary* locations, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1876 | DataType::Type type, |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1877 | bool is_volatile, |
| 1878 | CodeGeneratorX86* codegen) { |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 1879 | X86Assembler* assembler = down_cast<X86Assembler*>(codegen->GetAssembler()); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1880 | Register base = locations->InAt(1).AsRegister<Register>(); |
| 1881 | Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); |
| 1882 | Location value_loc = locations->InAt(3); |
| 1883 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1884 | if (type == DataType::Type::kInt64) { |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1885 | Register value_lo = value_loc.AsRegisterPairLow<Register>(); |
| 1886 | Register value_hi = value_loc.AsRegisterPairHigh<Register>(); |
| 1887 | if (is_volatile) { |
| 1888 | XmmRegister temp1 = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1889 | XmmRegister temp2 = locations->GetTemp(1).AsFpuRegister<XmmRegister>(); |
| 1890 | __ movd(temp1, value_lo); |
| 1891 | __ movd(temp2, value_hi); |
| 1892 | __ punpckldq(temp1, temp2); |
| 1893 | __ movsd(Address(base, offset, ScaleFactor::TIMES_1, 0), temp1); |
| 1894 | } else { |
| 1895 | __ movl(Address(base, offset, ScaleFactor::TIMES_1, 0), value_lo); |
| 1896 | __ movl(Address(base, offset, ScaleFactor::TIMES_1, 4), value_hi); |
| 1897 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1898 | } else if (kPoisonHeapReferences && type == DataType::Type::kReference) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1899 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1900 | __ movl(temp, value_loc.AsRegister<Register>()); |
| 1901 | __ PoisonHeapReference(temp); |
| 1902 | __ movl(Address(base, offset, ScaleFactor::TIMES_1, 0), temp); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1903 | } else { |
| 1904 | __ movl(Address(base, offset, ScaleFactor::TIMES_1, 0), value_loc.AsRegister<Register>()); |
| 1905 | } |
| 1906 | |
| 1907 | if (is_volatile) { |
Mark P Mendell | 17077d8 | 2015-12-16 19:15:59 +0000 | [diff] [blame] | 1908 | codegen->MemoryFence(); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1909 | } |
| 1910 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1911 | if (type == DataType::Type::kReference) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1912 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1913 | codegen->MarkGCCard(locations->GetTemp(0).AsRegister<Register>(), |
| 1914 | locations->GetTemp(1).AsRegister<Register>(), |
| 1915 | base, |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1916 | value_loc.AsRegister<Register>(), |
| 1917 | value_can_be_null); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | void IntrinsicCodeGeneratorX86::VisitUnsafePut(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1922 | GenUnsafePut(invoke->GetLocations(), DataType::Type::kInt32, /* is_volatile= */ false, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1923 | } |
| 1924 | void IntrinsicCodeGeneratorX86::VisitUnsafePutOrdered(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1925 | GenUnsafePut(invoke->GetLocations(), DataType::Type::kInt32, /* is_volatile= */ false, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1926 | } |
| 1927 | void IntrinsicCodeGeneratorX86::VisitUnsafePutVolatile(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1928 | GenUnsafePut(invoke->GetLocations(), DataType::Type::kInt32, /* is_volatile= */ true, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1929 | } |
| 1930 | void IntrinsicCodeGeneratorX86::VisitUnsafePutObject(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1931 | GenUnsafePut( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1932 | invoke->GetLocations(), DataType::Type::kReference, /* is_volatile= */ false, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1933 | } |
| 1934 | void IntrinsicCodeGeneratorX86::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1935 | GenUnsafePut( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1936 | invoke->GetLocations(), DataType::Type::kReference, /* is_volatile= */ false, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1937 | } |
| 1938 | void IntrinsicCodeGeneratorX86::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1939 | GenUnsafePut( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1940 | invoke->GetLocations(), DataType::Type::kReference, /* is_volatile= */ true, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1941 | } |
| 1942 | void IntrinsicCodeGeneratorX86::VisitUnsafePutLong(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1943 | GenUnsafePut(invoke->GetLocations(), DataType::Type::kInt64, /* is_volatile= */ false, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1944 | } |
| 1945 | void IntrinsicCodeGeneratorX86::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1946 | GenUnsafePut(invoke->GetLocations(), DataType::Type::kInt64, /* is_volatile= */ false, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1947 | } |
| 1948 | void IntrinsicCodeGeneratorX86::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 1949 | GenUnsafePut(invoke->GetLocations(), DataType::Type::kInt64, /* is_volatile= */ true, codegen_); |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 1950 | } |
| 1951 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1952 | static void CreateIntIntIntIntIntToInt(ArenaAllocator* allocator, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1953 | DataType::Type type, |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 1954 | HInvoke* invoke) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1955 | bool can_call = kEmitCompilerReadBarrier && |
| 1956 | kUseBakerReadBarrier && |
| 1957 | (invoke->GetIntrinsic() == Intrinsics::kUnsafeCASObject); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1958 | LocationSummary* locations = |
| 1959 | new (allocator) LocationSummary(invoke, |
| 1960 | can_call |
| 1961 | ? LocationSummary::kCallOnSlowPath |
| 1962 | : LocationSummary::kNoCall, |
| 1963 | kIntrinsified); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 1964 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 1965 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1966 | // Offset is a long, but in 32 bit mode, we only need the low word. |
| 1967 | // Can we update the invoke here to remove a TypeConvert to Long? |
| 1968 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1969 | // Expected value must be in EAX or EDX:EAX. |
| 1970 | // For long, new value must be in ECX:EBX. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1971 | if (type == DataType::Type::kInt64) { |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 1972 | locations->SetInAt(3, Location::RegisterPairLocation(EAX, EDX)); |
| 1973 | locations->SetInAt(4, Location::RegisterPairLocation(EBX, ECX)); |
| 1974 | } else { |
| 1975 | locations->SetInAt(3, Location::RegisterLocation(EAX)); |
| 1976 | locations->SetInAt(4, Location::RequiresRegister()); |
| 1977 | } |
| 1978 | |
| 1979 | // Force a byte register for the output. |
| 1980 | locations->SetOut(Location::RegisterLocation(EAX)); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1981 | if (type == DataType::Type::kReference) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1982 | // Need temporary registers for card-marking, and possibly for |
| 1983 | // (Baker) read barrier. |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 1984 | locations->AddTemp(Location::RequiresRegister()); // Possibly used for reference poisoning too. |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 1985 | // Need a byte register for marking. |
| 1986 | locations->AddTemp(Location::RegisterLocation(ECX)); |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | void IntrinsicLocationsBuilderX86::VisitUnsafeCASInt(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1991 | CreateIntIntIntIntIntToInt(allocator_, DataType::Type::kInt32, invoke); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | void IntrinsicLocationsBuilderX86::VisitUnsafeCASLong(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1995 | CreateIntIntIntIntIntToInt(allocator_, DataType::Type::kInt64, invoke); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | void IntrinsicLocationsBuilderX86::VisitUnsafeCASObject(HInvoke* invoke) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1999 | // The only read barrier implementation supporting the |
| 2000 | // UnsafeCASObject intrinsic is the Baker-style read barriers. |
| 2001 | if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) { |
Roland Levillain | 391b866 | 2015-12-18 11:43:38 +0000 | [diff] [blame] | 2002 | return; |
| 2003 | } |
| 2004 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2005 | CreateIntIntIntIntIntToInt(allocator_, DataType::Type::kReference, invoke); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2006 | } |
| 2007 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2008 | static void GenCAS(DataType::Type type, HInvoke* invoke, CodeGeneratorX86* codegen) { |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2009 | X86Assembler* assembler = down_cast<X86Assembler*>(codegen->GetAssembler()); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2010 | LocationSummary* locations = invoke->GetLocations(); |
| 2011 | |
| 2012 | Register base = locations->InAt(1).AsRegister<Register>(); |
| 2013 | Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); |
| 2014 | Location out = locations->Out(); |
| 2015 | DCHECK_EQ(out.AsRegister<Register>(), EAX); |
| 2016 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2017 | // The address of the field within the holding object. |
| 2018 | Address field_addr(base, offset, ScaleFactor::TIMES_1, 0); |
| 2019 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2020 | if (type == DataType::Type::kReference) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2021 | // The only read barrier implementation supporting the |
| 2022 | // UnsafeCASObject intrinsic is the Baker-style read barriers. |
| 2023 | DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier); |
| 2024 | |
| 2025 | Location temp1_loc = locations->GetTemp(0); |
| 2026 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 2027 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 2028 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2029 | Register expected = locations->InAt(3).AsRegister<Register>(); |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2030 | // Ensure `expected` is in EAX (required by the CMPXCHG instruction). |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2031 | DCHECK_EQ(expected, EAX); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2032 | Register value = locations->InAt(4).AsRegister<Register>(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2033 | |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2034 | // Mark card for object assuming new value is stored. |
| 2035 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2036 | codegen->MarkGCCard(temp1, temp2, base, value, value_can_be_null); |
| 2037 | |
| 2038 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2039 | // Need to make sure the reference stored in the field is a to-space |
| 2040 | // one before attempting the CAS or the CAS could fail incorrectly. |
| 2041 | codegen->GenerateReferenceLoadWithBakerReadBarrier( |
| 2042 | invoke, |
| 2043 | temp1_loc, // Unused, used only as a "temporary" within the read barrier. |
| 2044 | base, |
| 2045 | field_addr, |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2046 | /* needs_null_check= */ false, |
| 2047 | /* always_update_field= */ true, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2048 | &temp2); |
| 2049 | } |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2050 | |
| 2051 | bool base_equals_value = (base == value); |
| 2052 | if (kPoisonHeapReferences) { |
| 2053 | if (base_equals_value) { |
| 2054 | // If `base` and `value` are the same register location, move |
| 2055 | // `value` to a temporary register. This way, poisoning |
| 2056 | // `value` won't invalidate `base`. |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2057 | value = temp1; |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2058 | __ movl(value, base); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2059 | } |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2060 | |
| 2061 | // Check that the register allocator did not assign the location |
| 2062 | // of `expected` (EAX) to `value` nor to `base`, so that heap |
| 2063 | // poisoning (when enabled) works as intended below. |
| 2064 | // - If `value` were equal to `expected`, both references would |
| 2065 | // be poisoned twice, meaning they would not be poisoned at |
| 2066 | // all, as heap poisoning uses address negation. |
| 2067 | // - If `base` were equal to `expected`, poisoning `expected` |
| 2068 | // would invalidate `base`. |
| 2069 | DCHECK_NE(value, expected); |
| 2070 | DCHECK_NE(base, expected); |
| 2071 | |
| 2072 | __ PoisonHeapReference(expected); |
| 2073 | __ PoisonHeapReference(value); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2074 | } |
| 2075 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2076 | __ LockCmpxchgl(field_addr, value); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2077 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2078 | // LOCK CMPXCHG has full barrier semantics, and we don't need |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2079 | // scheduling barriers at this time. |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2080 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2081 | // Convert ZF into the Boolean result. |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2082 | __ setb(kZero, out.AsRegister<Register>()); |
| 2083 | __ movzxb(out.AsRegister<Register>(), out.AsRegister<ByteRegister>()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2084 | |
Roland Levillain | 391b866 | 2015-12-18 11:43:38 +0000 | [diff] [blame] | 2085 | // If heap poisoning is enabled, we need to unpoison the values |
| 2086 | // that were poisoned earlier. |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2087 | if (kPoisonHeapReferences) { |
| 2088 | if (base_equals_value) { |
| 2089 | // `value` has been moved to a temporary register, no need to |
| 2090 | // unpoison it. |
| 2091 | } else { |
| 2092 | // Ensure `value` is different from `out`, so that unpoisoning |
| 2093 | // the former does not invalidate the latter. |
| 2094 | DCHECK_NE(value, out.AsRegister<Register>()); |
| 2095 | __ UnpoisonHeapReference(value); |
| 2096 | } |
| 2097 | // Do not unpoison the reference contained in register |
| 2098 | // `expected`, as it is the same as register `out` (EAX). |
| 2099 | } |
| 2100 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2101 | if (type == DataType::Type::kInt32) { |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2102 | // Ensure the expected value is in EAX (required by the CMPXCHG |
| 2103 | // instruction). |
| 2104 | DCHECK_EQ(locations->InAt(3).AsRegister<Register>(), EAX); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2105 | __ LockCmpxchgl(field_addr, locations->InAt(4).AsRegister<Register>()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2106 | } else if (type == DataType::Type::kInt64) { |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2107 | // Ensure the expected value is in EAX:EDX and that the new |
| 2108 | // value is in EBX:ECX (required by the CMPXCHG8B instruction). |
| 2109 | DCHECK_EQ(locations->InAt(3).AsRegisterPairLow<Register>(), EAX); |
| 2110 | DCHECK_EQ(locations->InAt(3).AsRegisterPairHigh<Register>(), EDX); |
| 2111 | DCHECK_EQ(locations->InAt(4).AsRegisterPairLow<Register>(), EBX); |
| 2112 | DCHECK_EQ(locations->InAt(4).AsRegisterPairHigh<Register>(), ECX); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2113 | __ LockCmpxchg8b(field_addr); |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2114 | } else { |
| 2115 | LOG(FATAL) << "Unexpected CAS type " << type; |
| 2116 | } |
| 2117 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 2118 | // LOCK CMPXCHG/LOCK CMPXCHG8B have full barrier semantics, and we |
| 2119 | // don't need scheduling barriers at this time. |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2120 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2121 | // Convert ZF into the Boolean result. |
Roland Levillain | b488b78 | 2015-10-22 11:38:49 +0100 | [diff] [blame] | 2122 | __ setb(kZero, out.AsRegister<Register>()); |
| 2123 | __ movzxb(out.AsRegister<Register>(), out.AsRegister<ByteRegister>()); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2124 | } |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | void IntrinsicCodeGeneratorX86::VisitUnsafeCASInt(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2128 | GenCAS(DataType::Type::kInt32, invoke, codegen_); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | void IntrinsicCodeGeneratorX86::VisitUnsafeCASLong(HInvoke* invoke) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2132 | GenCAS(DataType::Type::kInt64, invoke, codegen_); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | void IntrinsicCodeGeneratorX86::VisitUnsafeCASObject(HInvoke* invoke) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 2136 | // The only read barrier implementation supporting the |
| 2137 | // UnsafeCASObject intrinsic is the Baker-style read barriers. |
| 2138 | DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 2139 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2140 | GenCAS(DataType::Type::kReference, invoke, codegen_); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | void IntrinsicLocationsBuilderX86::VisitIntegerReverse(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2144 | LocationSummary* locations = |
| 2145 | new (allocator_) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2146 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2147 | locations->SetOut(Location::SameAsFirstInput()); |
| 2148 | locations->AddTemp(Location::RequiresRegister()); |
| 2149 | } |
| 2150 | |
| 2151 | static void SwapBits(Register reg, Register temp, int32_t shift, int32_t mask, |
| 2152 | X86Assembler* assembler) { |
| 2153 | Immediate imm_shift(shift); |
| 2154 | Immediate imm_mask(mask); |
| 2155 | __ movl(temp, reg); |
| 2156 | __ shrl(reg, imm_shift); |
| 2157 | __ andl(temp, imm_mask); |
| 2158 | __ andl(reg, imm_mask); |
| 2159 | __ shll(temp, imm_shift); |
| 2160 | __ orl(reg, temp); |
| 2161 | } |
| 2162 | |
| 2163 | void IntrinsicCodeGeneratorX86::VisitIntegerReverse(HInvoke* invoke) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2164 | X86Assembler* assembler = GetAssembler(); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2165 | LocationSummary* locations = invoke->GetLocations(); |
| 2166 | |
| 2167 | Register reg = locations->InAt(0).AsRegister<Register>(); |
| 2168 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2169 | |
| 2170 | /* |
| 2171 | * Use one bswap instruction to reverse byte order first and then use 3 rounds of |
| 2172 | * swapping bits to reverse bits in a number x. Using bswap to save instructions |
| 2173 | * compared to generic luni implementation which has 5 rounds of swapping bits. |
| 2174 | * x = bswap x |
| 2175 | * x = (x & 0x55555555) << 1 | (x >> 1) & 0x55555555; |
| 2176 | * x = (x & 0x33333333) << 2 | (x >> 2) & 0x33333333; |
| 2177 | * x = (x & 0x0F0F0F0F) << 4 | (x >> 4) & 0x0F0F0F0F; |
| 2178 | */ |
| 2179 | __ bswapl(reg); |
| 2180 | SwapBits(reg, temp, 1, 0x55555555, assembler); |
| 2181 | SwapBits(reg, temp, 2, 0x33333333, assembler); |
| 2182 | SwapBits(reg, temp, 4, 0x0f0f0f0f, assembler); |
| 2183 | } |
| 2184 | |
| 2185 | void IntrinsicLocationsBuilderX86::VisitLongReverse(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2186 | LocationSummary* locations = |
| 2187 | new (allocator_) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2188 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2189 | locations->SetOut(Location::SameAsFirstInput()); |
| 2190 | locations->AddTemp(Location::RequiresRegister()); |
| 2191 | } |
| 2192 | |
| 2193 | void IntrinsicCodeGeneratorX86::VisitLongReverse(HInvoke* invoke) { |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2194 | X86Assembler* assembler = GetAssembler(); |
Mark Mendell | 58d25fd | 2015-04-03 14:52:31 -0400 | [diff] [blame] | 2195 | LocationSummary* locations = invoke->GetLocations(); |
| 2196 | |
| 2197 | Register reg_low = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2198 | Register reg_high = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2199 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2200 | |
| 2201 | // We want to swap high/low, then bswap each one, and then do the same |
| 2202 | // as a 32 bit reverse. |
| 2203 | // Exchange high and low. |
| 2204 | __ movl(temp, reg_low); |
| 2205 | __ movl(reg_low, reg_high); |
| 2206 | __ movl(reg_high, temp); |
| 2207 | |
| 2208 | // bit-reverse low |
| 2209 | __ bswapl(reg_low); |
| 2210 | SwapBits(reg_low, temp, 1, 0x55555555, assembler); |
| 2211 | SwapBits(reg_low, temp, 2, 0x33333333, assembler); |
| 2212 | SwapBits(reg_low, temp, 4, 0x0f0f0f0f, assembler); |
| 2213 | |
| 2214 | // bit-reverse high |
| 2215 | __ bswapl(reg_high); |
| 2216 | SwapBits(reg_high, temp, 1, 0x55555555, assembler); |
| 2217 | SwapBits(reg_high, temp, 2, 0x33333333, assembler); |
| 2218 | SwapBits(reg_high, temp, 4, 0x0f0f0f0f, assembler); |
| 2219 | } |
| 2220 | |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2221 | static void CreateBitCountLocations( |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2222 | ArenaAllocator* allocator, CodeGeneratorX86* codegen, HInvoke* invoke, bool is_long) { |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2223 | if (!codegen->GetInstructionSetFeatures().HasPopCnt()) { |
| 2224 | // Do nothing if there is no popcnt support. This results in generating |
| 2225 | // a call for the intrinsic rather than direct code. |
| 2226 | return; |
| 2227 | } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2228 | LocationSummary* locations = |
| 2229 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2230 | if (is_long) { |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2231 | locations->AddTemp(Location::RequiresRegister()); |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2232 | } |
Aart Bik | 2a94607 | 2016-01-21 12:49:00 -0800 | [diff] [blame] | 2233 | locations->SetInAt(0, Location::Any()); |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2234 | locations->SetOut(Location::RequiresRegister()); |
| 2235 | } |
| 2236 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2237 | static void GenBitCount(X86Assembler* assembler, |
| 2238 | CodeGeneratorX86* codegen, |
| 2239 | HInvoke* invoke, bool is_long) { |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2240 | LocationSummary* locations = invoke->GetLocations(); |
| 2241 | Location src = locations->InAt(0); |
| 2242 | Register out = locations->Out().AsRegister<Register>(); |
| 2243 | |
| 2244 | if (invoke->InputAt(0)->IsConstant()) { |
| 2245 | // Evaluate this at compile time. |
| 2246 | int64_t value = Int64FromConstant(invoke->InputAt(0)->AsConstant()); |
Roland Levillain | fa3912e | 2016-04-01 18:21:55 +0100 | [diff] [blame] | 2247 | int32_t result = is_long |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2248 | ? POPCOUNT(static_cast<uint64_t>(value)) |
| 2249 | : POPCOUNT(static_cast<uint32_t>(value)); |
Roland Levillain | fa3912e | 2016-04-01 18:21:55 +0100 | [diff] [blame] | 2250 | codegen->Load32BitValue(out, result); |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2251 | return; |
| 2252 | } |
| 2253 | |
| 2254 | // Handle the non-constant cases. |
| 2255 | if (!is_long) { |
| 2256 | if (src.IsRegister()) { |
| 2257 | __ popcntl(out, src.AsRegister<Register>()); |
| 2258 | } else { |
| 2259 | DCHECK(src.IsStackSlot()); |
| 2260 | __ popcntl(out, Address(ESP, src.GetStackIndex())); |
| 2261 | } |
Aart Bik | 2a94607 | 2016-01-21 12:49:00 -0800 | [diff] [blame] | 2262 | } else { |
| 2263 | // The 64-bit case needs to worry about two parts. |
| 2264 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 2265 | if (src.IsRegisterPair()) { |
| 2266 | __ popcntl(temp, src.AsRegisterPairLow<Register>()); |
| 2267 | __ popcntl(out, src.AsRegisterPairHigh<Register>()); |
| 2268 | } else { |
| 2269 | DCHECK(src.IsDoubleStackSlot()); |
| 2270 | __ popcntl(temp, Address(ESP, src.GetStackIndex())); |
| 2271 | __ popcntl(out, Address(ESP, src.GetHighStackIndex(kX86WordSize))); |
| 2272 | } |
| 2273 | __ addl(out, temp); |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2274 | } |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | void IntrinsicLocationsBuilderX86::VisitIntegerBitCount(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2278 | CreateBitCountLocations(allocator_, codegen_, invoke, /* is_long= */ false); |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | void IntrinsicCodeGeneratorX86::VisitIntegerBitCount(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2282 | GenBitCount(GetAssembler(), codegen_, invoke, /* is_long= */ false); |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | void IntrinsicLocationsBuilderX86::VisitLongBitCount(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2286 | CreateBitCountLocations(allocator_, codegen_, invoke, /* is_long= */ true); |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | void IntrinsicCodeGeneratorX86::VisitLongBitCount(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2290 | GenBitCount(GetAssembler(), codegen_, invoke, /* is_long= */ true); |
Aart Bik | c39dac1 | 2016-01-21 08:59:48 -0800 | [diff] [blame] | 2291 | } |
| 2292 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2293 | static void CreateLeadingZeroLocations(ArenaAllocator* allocator, HInvoke* invoke, bool is_long) { |
| 2294 | LocationSummary* locations = |
| 2295 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 2296 | if (is_long) { |
| 2297 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2298 | } else { |
| 2299 | locations->SetInAt(0, Location::Any()); |
| 2300 | } |
| 2301 | locations->SetOut(Location::RequiresRegister()); |
| 2302 | } |
| 2303 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2304 | static void GenLeadingZeros(X86Assembler* assembler, |
| 2305 | CodeGeneratorX86* codegen, |
| 2306 | HInvoke* invoke, bool is_long) { |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 2307 | LocationSummary* locations = invoke->GetLocations(); |
| 2308 | Location src = locations->InAt(0); |
| 2309 | Register out = locations->Out().AsRegister<Register>(); |
| 2310 | |
| 2311 | if (invoke->InputAt(0)->IsConstant()) { |
| 2312 | // Evaluate this at compile time. |
| 2313 | int64_t value = Int64FromConstant(invoke->InputAt(0)->AsConstant()); |
| 2314 | if (value == 0) { |
| 2315 | value = is_long ? 64 : 32; |
| 2316 | } else { |
| 2317 | value = is_long ? CLZ(static_cast<uint64_t>(value)) : CLZ(static_cast<uint32_t>(value)); |
| 2318 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2319 | codegen->Load32BitValue(out, value); |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 2320 | return; |
| 2321 | } |
| 2322 | |
| 2323 | // Handle the non-constant cases. |
| 2324 | if (!is_long) { |
| 2325 | if (src.IsRegister()) { |
| 2326 | __ bsrl(out, src.AsRegister<Register>()); |
| 2327 | } else { |
| 2328 | DCHECK(src.IsStackSlot()); |
| 2329 | __ bsrl(out, Address(ESP, src.GetStackIndex())); |
| 2330 | } |
| 2331 | |
| 2332 | // BSR sets ZF if the input was zero, and the output is undefined. |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2333 | NearLabel all_zeroes, done; |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 2334 | __ j(kEqual, &all_zeroes); |
| 2335 | |
| 2336 | // Correct the result from BSR to get the final CLZ result. |
| 2337 | __ xorl(out, Immediate(31)); |
| 2338 | __ jmp(&done); |
| 2339 | |
| 2340 | // Fix the zero case with the expected result. |
| 2341 | __ Bind(&all_zeroes); |
| 2342 | __ movl(out, Immediate(32)); |
| 2343 | |
| 2344 | __ Bind(&done); |
| 2345 | return; |
| 2346 | } |
| 2347 | |
| 2348 | // 64 bit case needs to worry about both parts of the register. |
| 2349 | DCHECK(src.IsRegisterPair()); |
| 2350 | Register src_lo = src.AsRegisterPairLow<Register>(); |
| 2351 | Register src_hi = src.AsRegisterPairHigh<Register>(); |
Mark Mendell | 0c9497d | 2015-08-21 09:30:05 -0400 | [diff] [blame] | 2352 | NearLabel handle_low, done, all_zeroes; |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 2353 | |
| 2354 | // Is the high word zero? |
| 2355 | __ testl(src_hi, src_hi); |
| 2356 | __ j(kEqual, &handle_low); |
| 2357 | |
| 2358 | // High word is not zero. We know that the BSR result is defined in this case. |
| 2359 | __ bsrl(out, src_hi); |
| 2360 | |
| 2361 | // Correct the result from BSR to get the final CLZ result. |
| 2362 | __ xorl(out, Immediate(31)); |
| 2363 | __ jmp(&done); |
| 2364 | |
| 2365 | // High word was zero. We have to compute the low word count and add 32. |
| 2366 | __ Bind(&handle_low); |
| 2367 | __ bsrl(out, src_lo); |
| 2368 | __ j(kEqual, &all_zeroes); |
| 2369 | |
| 2370 | // We had a valid result. Use an XOR to both correct the result and add 32. |
| 2371 | __ xorl(out, Immediate(63)); |
| 2372 | __ jmp(&done); |
| 2373 | |
| 2374 | // All zero case. |
| 2375 | __ Bind(&all_zeroes); |
| 2376 | __ movl(out, Immediate(64)); |
| 2377 | |
| 2378 | __ Bind(&done); |
| 2379 | } |
| 2380 | |
| 2381 | void IntrinsicLocationsBuilderX86::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2382 | CreateLeadingZeroLocations(allocator_, invoke, /* is_long= */ false); |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | void IntrinsicCodeGeneratorX86::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2386 | GenLeadingZeros(GetAssembler(), codegen_, invoke, /* is_long= */ false); |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | void IntrinsicLocationsBuilderX86::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2390 | CreateLeadingZeroLocations(allocator_, invoke, /* is_long= */ true); |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | void IntrinsicCodeGeneratorX86::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2394 | GenLeadingZeros(GetAssembler(), codegen_, invoke, /* is_long= */ true); |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 2395 | } |
| 2396 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2397 | static void CreateTrailingZeroLocations(ArenaAllocator* allocator, HInvoke* invoke, bool is_long) { |
| 2398 | LocationSummary* locations = |
| 2399 | new (allocator) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Mark Mendell | 2d55479 | 2015-09-15 21:45:18 -0400 | [diff] [blame] | 2400 | if (is_long) { |
| 2401 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2402 | } else { |
| 2403 | locations->SetInAt(0, Location::Any()); |
| 2404 | } |
| 2405 | locations->SetOut(Location::RequiresRegister()); |
| 2406 | } |
| 2407 | |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2408 | static void GenTrailingZeros(X86Assembler* assembler, |
| 2409 | CodeGeneratorX86* codegen, |
| 2410 | HInvoke* invoke, bool is_long) { |
Mark Mendell | 2d55479 | 2015-09-15 21:45:18 -0400 | [diff] [blame] | 2411 | LocationSummary* locations = invoke->GetLocations(); |
| 2412 | Location src = locations->InAt(0); |
| 2413 | Register out = locations->Out().AsRegister<Register>(); |
| 2414 | |
| 2415 | if (invoke->InputAt(0)->IsConstant()) { |
| 2416 | // Evaluate this at compile time. |
| 2417 | int64_t value = Int64FromConstant(invoke->InputAt(0)->AsConstant()); |
| 2418 | if (value == 0) { |
| 2419 | value = is_long ? 64 : 32; |
| 2420 | } else { |
| 2421 | value = is_long ? CTZ(static_cast<uint64_t>(value)) : CTZ(static_cast<uint32_t>(value)); |
| 2422 | } |
Aart Bik | a19616e | 2016-02-01 18:57:58 -0800 | [diff] [blame] | 2423 | codegen->Load32BitValue(out, value); |
Mark Mendell | 2d55479 | 2015-09-15 21:45:18 -0400 | [diff] [blame] | 2424 | return; |
| 2425 | } |
| 2426 | |
| 2427 | // Handle the non-constant cases. |
| 2428 | if (!is_long) { |
| 2429 | if (src.IsRegister()) { |
| 2430 | __ bsfl(out, src.AsRegister<Register>()); |
| 2431 | } else { |
| 2432 | DCHECK(src.IsStackSlot()); |
| 2433 | __ bsfl(out, Address(ESP, src.GetStackIndex())); |
| 2434 | } |
| 2435 | |
| 2436 | // BSF sets ZF if the input was zero, and the output is undefined. |
| 2437 | NearLabel done; |
| 2438 | __ j(kNotEqual, &done); |
| 2439 | |
| 2440 | // Fix the zero case with the expected result. |
| 2441 | __ movl(out, Immediate(32)); |
| 2442 | |
| 2443 | __ Bind(&done); |
| 2444 | return; |
| 2445 | } |
| 2446 | |
| 2447 | // 64 bit case needs to worry about both parts of the register. |
| 2448 | DCHECK(src.IsRegisterPair()); |
| 2449 | Register src_lo = src.AsRegisterPairLow<Register>(); |
| 2450 | Register src_hi = src.AsRegisterPairHigh<Register>(); |
| 2451 | NearLabel done, all_zeroes; |
| 2452 | |
| 2453 | // If the low word is zero, then ZF will be set. If not, we have the answer. |
| 2454 | __ bsfl(out, src_lo); |
| 2455 | __ j(kNotEqual, &done); |
| 2456 | |
| 2457 | // Low word was zero. We have to compute the high word count and add 32. |
| 2458 | __ bsfl(out, src_hi); |
| 2459 | __ j(kEqual, &all_zeroes); |
| 2460 | |
| 2461 | // We had a valid result. Add 32 to account for the low word being zero. |
| 2462 | __ addl(out, Immediate(32)); |
| 2463 | __ jmp(&done); |
| 2464 | |
| 2465 | // All zero case. |
| 2466 | __ Bind(&all_zeroes); |
| 2467 | __ movl(out, Immediate(64)); |
| 2468 | |
| 2469 | __ Bind(&done); |
| 2470 | } |
| 2471 | |
| 2472 | void IntrinsicLocationsBuilderX86::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2473 | CreateTrailingZeroLocations(allocator_, invoke, /* is_long= */ false); |
Mark Mendell | 2d55479 | 2015-09-15 21:45:18 -0400 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | void IntrinsicCodeGeneratorX86::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2477 | GenTrailingZeros(GetAssembler(), codegen_, invoke, /* is_long= */ false); |
Mark Mendell | 2d55479 | 2015-09-15 21:45:18 -0400 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | void IntrinsicLocationsBuilderX86::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2481 | CreateTrailingZeroLocations(allocator_, invoke, /* is_long= */ true); |
Mark Mendell | 2d55479 | 2015-09-15 21:45:18 -0400 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | void IntrinsicCodeGeneratorX86::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2485 | GenTrailingZeros(GetAssembler(), codegen_, invoke, /* is_long= */ true); |
Mark Mendell | 2d55479 | 2015-09-15 21:45:18 -0400 | [diff] [blame] | 2486 | } |
| 2487 | |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2488 | static bool IsSameInput(HInstruction* instruction, size_t input0, size_t input1) { |
| 2489 | return instruction->InputAt(input0) == instruction->InputAt(input1); |
| 2490 | } |
| 2491 | |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2492 | // Compute base address for the System.arraycopy intrinsic in `base`. |
| 2493 | static void GenSystemArrayCopyBaseAddress(X86Assembler* assembler, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2494 | DataType::Type type, |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2495 | const Register& array, |
| 2496 | const Location& pos, |
| 2497 | const Register& base) { |
| 2498 | // This routine is only used by the SystemArrayCopy intrinsic at the |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2499 | // moment. We can allow DataType::Type::kReference as `type` to implement |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2500 | // the SystemArrayCopyChar intrinsic. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2501 | DCHECK_EQ(type, DataType::Type::kReference); |
| 2502 | const int32_t element_size = DataType::Size(type); |
| 2503 | const ScaleFactor scale_factor = static_cast<ScaleFactor>(DataType::SizeShift(type)); |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2504 | const uint32_t data_offset = mirror::Array::DataOffset(element_size).Uint32Value(); |
| 2505 | |
| 2506 | if (pos.IsConstant()) { |
| 2507 | int32_t constant = pos.GetConstant()->AsIntConstant()->GetValue(); |
| 2508 | __ leal(base, Address(array, element_size * constant + data_offset)); |
| 2509 | } else { |
| 2510 | __ leal(base, Address(array, pos.AsRegister<Register>(), scale_factor, data_offset)); |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | // Compute end source address for the System.arraycopy intrinsic in `end`. |
| 2515 | static void GenSystemArrayCopyEndAddress(X86Assembler* assembler, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2516 | DataType::Type type, |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2517 | const Location& copy_length, |
| 2518 | const Register& base, |
| 2519 | const Register& end) { |
| 2520 | // This routine is only used by the SystemArrayCopy intrinsic at the |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2521 | // moment. We can allow DataType::Type::kReference as `type` to implement |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2522 | // the SystemArrayCopyChar intrinsic. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2523 | DCHECK_EQ(type, DataType::Type::kReference); |
| 2524 | const int32_t element_size = DataType::Size(type); |
| 2525 | const ScaleFactor scale_factor = static_cast<ScaleFactor>(DataType::SizeShift(type)); |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2526 | |
| 2527 | if (copy_length.IsConstant()) { |
| 2528 | int32_t constant = copy_length.GetConstant()->AsIntConstant()->GetValue(); |
| 2529 | __ leal(end, Address(base, element_size * constant)); |
| 2530 | } else { |
| 2531 | __ leal(end, Address(base, copy_length.AsRegister<Register>(), scale_factor, 0)); |
| 2532 | } |
| 2533 | } |
| 2534 | |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2535 | void IntrinsicLocationsBuilderX86::VisitSystemArrayCopy(HInvoke* invoke) { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2536 | // The only read barrier implementation supporting the |
| 2537 | // SystemArrayCopy intrinsic is the Baker-style read barriers. |
| 2538 | if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) { |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2539 | return; |
| 2540 | } |
| 2541 | |
| 2542 | CodeGenerator::CreateSystemArrayCopyLocationSummary(invoke); |
| 2543 | if (invoke->GetLocations() != nullptr) { |
| 2544 | // Need a byte register for marking. |
| 2545 | invoke->GetLocations()->SetTempAt(1, Location::RegisterLocation(ECX)); |
| 2546 | |
| 2547 | static constexpr size_t kSrc = 0; |
| 2548 | static constexpr size_t kSrcPos = 1; |
| 2549 | static constexpr size_t kDest = 2; |
| 2550 | static constexpr size_t kDestPos = 3; |
| 2551 | static constexpr size_t kLength = 4; |
| 2552 | |
| 2553 | if (!invoke->InputAt(kSrcPos)->IsIntConstant() && |
| 2554 | !invoke->InputAt(kDestPos)->IsIntConstant() && |
| 2555 | !invoke->InputAt(kLength)->IsIntConstant()) { |
| 2556 | if (!IsSameInput(invoke, kSrcPos, kDestPos) && |
| 2557 | !IsSameInput(invoke, kSrcPos, kLength) && |
| 2558 | !IsSameInput(invoke, kDestPos, kLength) && |
| 2559 | !IsSameInput(invoke, kSrc, kDest)) { |
| 2560 | // Not enough registers, make the length also take a stack slot. |
| 2561 | invoke->GetLocations()->SetInAt(kLength, Location::Any()); |
| 2562 | } |
| 2563 | } |
| 2564 | } |
| 2565 | } |
| 2566 | |
| 2567 | void IntrinsicCodeGeneratorX86::VisitSystemArrayCopy(HInvoke* invoke) { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2568 | // The only read barrier implementation supporting the |
| 2569 | // SystemArrayCopy intrinsic is the Baker-style read barriers. |
| 2570 | DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2571 | |
| 2572 | X86Assembler* assembler = GetAssembler(); |
| 2573 | LocationSummary* locations = invoke->GetLocations(); |
| 2574 | |
| 2575 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2576 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2577 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2578 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2579 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2580 | |
| 2581 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 2582 | Location src_pos = locations->InAt(1); |
| 2583 | Register dest = locations->InAt(2).AsRegister<Register>(); |
| 2584 | Location dest_pos = locations->InAt(3); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2585 | Location length_arg = locations->InAt(4); |
| 2586 | Location length = length_arg; |
| 2587 | Location temp1_loc = locations->GetTemp(0); |
| 2588 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 2589 | Location temp2_loc = locations->GetTemp(1); |
| 2590 | Register temp2 = temp2_loc.AsRegister<Register>(); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2591 | |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2592 | SlowPathCode* intrinsic_slow_path = |
| 2593 | new (codegen_->GetScopedAllocator()) IntrinsicSlowPathX86(invoke); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2594 | codegen_->AddSlowPath(intrinsic_slow_path); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2595 | |
| 2596 | NearLabel conditions_on_positions_validated; |
| 2597 | SystemArrayCopyOptimizations optimizations(invoke); |
| 2598 | |
| 2599 | // If source and destination are the same, we go to slow path if we need to do |
| 2600 | // forward copying. |
| 2601 | if (src_pos.IsConstant()) { |
| 2602 | int32_t src_pos_constant = src_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 2603 | if (dest_pos.IsConstant()) { |
| 2604 | int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 2605 | if (optimizations.GetDestinationIsSource()) { |
| 2606 | // Checked when building locations. |
| 2607 | DCHECK_GE(src_pos_constant, dest_pos_constant); |
| 2608 | } else if (src_pos_constant < dest_pos_constant) { |
| 2609 | __ cmpl(src, dest); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2610 | __ j(kEqual, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2611 | } |
| 2612 | } else { |
| 2613 | if (!optimizations.GetDestinationIsSource()) { |
| 2614 | __ cmpl(src, dest); |
| 2615 | __ j(kNotEqual, &conditions_on_positions_validated); |
| 2616 | } |
| 2617 | __ cmpl(dest_pos.AsRegister<Register>(), Immediate(src_pos_constant)); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2618 | __ j(kGreater, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2619 | } |
| 2620 | } else { |
| 2621 | if (!optimizations.GetDestinationIsSource()) { |
| 2622 | __ cmpl(src, dest); |
| 2623 | __ j(kNotEqual, &conditions_on_positions_validated); |
| 2624 | } |
| 2625 | if (dest_pos.IsConstant()) { |
| 2626 | int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 2627 | __ cmpl(src_pos.AsRegister<Register>(), Immediate(dest_pos_constant)); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2628 | __ j(kLess, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2629 | } else { |
| 2630 | __ cmpl(src_pos.AsRegister<Register>(), dest_pos.AsRegister<Register>()); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2631 | __ j(kLess, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | __ Bind(&conditions_on_positions_validated); |
| 2636 | |
| 2637 | if (!optimizations.GetSourceIsNotNull()) { |
| 2638 | // Bail out if the source is null. |
| 2639 | __ testl(src, src); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2640 | __ j(kEqual, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) { |
| 2644 | // Bail out if the destination is null. |
| 2645 | __ testl(dest, dest); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2646 | __ j(kEqual, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2647 | } |
| 2648 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2649 | Location temp3_loc = locations->GetTemp(2); |
| 2650 | Register temp3 = temp3_loc.AsRegister<Register>(); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2651 | if (length.IsStackSlot()) { |
| 2652 | __ movl(temp3, Address(ESP, length.GetStackIndex())); |
| 2653 | length = Location::RegisterLocation(temp3); |
| 2654 | } |
| 2655 | |
| 2656 | // If the length is negative, bail out. |
| 2657 | // We have already checked in the LocationsBuilder for the constant case. |
| 2658 | if (!length.IsConstant() && |
| 2659 | !optimizations.GetCountIsSourceLength() && |
| 2660 | !optimizations.GetCountIsDestinationLength()) { |
| 2661 | __ testl(length.AsRegister<Register>(), length.AsRegister<Register>()); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2662 | __ j(kLess, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | // Validity checks: source. |
| 2666 | CheckPosition(assembler, |
| 2667 | src_pos, |
| 2668 | src, |
| 2669 | length, |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2670 | intrinsic_slow_path, |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2671 | temp1, |
| 2672 | optimizations.GetCountIsSourceLength()); |
| 2673 | |
| 2674 | // Validity checks: dest. |
| 2675 | CheckPosition(assembler, |
| 2676 | dest_pos, |
| 2677 | dest, |
| 2678 | length, |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2679 | intrinsic_slow_path, |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2680 | temp1, |
| 2681 | optimizations.GetCountIsDestinationLength()); |
| 2682 | |
| 2683 | if (!optimizations.GetDoesNotNeedTypeCheck()) { |
| 2684 | // Check whether all elements of the source array are assignable to the component |
| 2685 | // type of the destination array. We do two checks: the classes are the same, |
| 2686 | // or the destination is Object[]. If none of these checks succeed, we go to the |
| 2687 | // slow path. |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2688 | |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2689 | if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2690 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2691 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 2692 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2693 | invoke, temp1_loc, src, class_offset, /* needs_null_check= */ false); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2694 | // Bail out if the source is not a non primitive array. |
| 2695 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2696 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2697 | invoke, temp1_loc, temp1, component_offset, /* needs_null_check= */ false); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2698 | __ testl(temp1, temp1); |
| 2699 | __ j(kEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2700 | // If heap poisoning is enabled, `temp1` has been unpoisoned |
| 2701 | // by the the previous call to GenerateFieldLoadWithBakerReadBarrier. |
| 2702 | } else { |
| 2703 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 2704 | __ movl(temp1, Address(src, class_offset)); |
| 2705 | __ MaybeUnpoisonHeapReference(temp1); |
| 2706 | // Bail out if the source is not a non primitive array. |
| 2707 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2708 | __ movl(temp1, Address(temp1, component_offset)); |
| 2709 | __ testl(temp1, temp1); |
| 2710 | __ j(kEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2711 | __ MaybeUnpoisonHeapReference(temp1); |
| 2712 | } |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2713 | __ cmpw(Address(temp1, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2714 | __ j(kNotEqual, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2715 | } |
| 2716 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2717 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2718 | if (length.Equals(Location::RegisterLocation(temp3))) { |
| 2719 | // When Baker read barriers are enabled, register `temp3`, |
| 2720 | // which in the present case contains the `length` parameter, |
| 2721 | // will be overwritten below. Make the `length` location |
| 2722 | // reference the original stack location; it will be moved |
| 2723 | // back to `temp3` later if necessary. |
| 2724 | DCHECK(length_arg.IsStackSlot()); |
| 2725 | length = length_arg; |
| 2726 | } |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2727 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2728 | // /* HeapReference<Class> */ temp1 = dest->klass_ |
| 2729 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2730 | invoke, temp1_loc, dest, class_offset, /* needs_null_check= */ false); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2731 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2732 | if (!optimizations.GetDestinationIsNonPrimitiveArray()) { |
| 2733 | // Bail out if the destination is not a non primitive array. |
| 2734 | // |
| 2735 | // Register `temp1` is not trashed by the read barrier emitted |
| 2736 | // by GenerateFieldLoadWithBakerReadBarrier below, as that |
| 2737 | // method produces a call to a ReadBarrierMarkRegX entry point, |
| 2738 | // which saves all potentially live registers, including |
| 2739 | // temporaries such a `temp1`. |
| 2740 | // /* HeapReference<Class> */ temp2 = temp1->component_type_ |
| 2741 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2742 | invoke, temp2_loc, temp1, component_offset, /* needs_null_check= */ false); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2743 | __ testl(temp2, temp2); |
| 2744 | __ j(kEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2745 | // If heap poisoning is enabled, `temp2` has been unpoisoned |
| 2746 | // by the the previous call to GenerateFieldLoadWithBakerReadBarrier. |
| 2747 | __ cmpw(Address(temp2, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 2748 | __ j(kNotEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2749 | } |
| 2750 | |
| 2751 | // For the same reason given earlier, `temp1` is not trashed by the |
| 2752 | // read barrier emitted by GenerateFieldLoadWithBakerReadBarrier below. |
| 2753 | // /* HeapReference<Class> */ temp2 = src->klass_ |
| 2754 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2755 | invoke, temp2_loc, src, class_offset, /* needs_null_check= */ false); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2756 | // Note: if heap poisoning is on, we are comparing two unpoisoned references here. |
| 2757 | __ cmpl(temp1, temp2); |
| 2758 | |
| 2759 | if (optimizations.GetDestinationIsTypedObjectArray()) { |
| 2760 | NearLabel do_copy; |
| 2761 | __ j(kEqual, &do_copy); |
| 2762 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2763 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2764 | invoke, temp1_loc, temp1, component_offset, /* needs_null_check= */ false); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2765 | // We do not need to emit a read barrier for the following |
| 2766 | // heap reference load, as `temp1` is only used in a |
| 2767 | // comparison with null below, and this reference is not |
| 2768 | // kept afterwards. |
| 2769 | __ cmpl(Address(temp1, super_offset), Immediate(0)); |
| 2770 | __ j(kNotEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2771 | __ Bind(&do_copy); |
| 2772 | } else { |
| 2773 | __ j(kNotEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2774 | } |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2775 | } else { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2776 | // Non read barrier code. |
| 2777 | |
| 2778 | // /* HeapReference<Class> */ temp1 = dest->klass_ |
| 2779 | __ movl(temp1, Address(dest, class_offset)); |
| 2780 | if (!optimizations.GetDestinationIsNonPrimitiveArray()) { |
| 2781 | __ MaybeUnpoisonHeapReference(temp1); |
| 2782 | // Bail out if the destination is not a non primitive array. |
| 2783 | // /* HeapReference<Class> */ temp2 = temp1->component_type_ |
| 2784 | __ movl(temp2, Address(temp1, component_offset)); |
| 2785 | __ testl(temp2, temp2); |
| 2786 | __ j(kEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2787 | __ MaybeUnpoisonHeapReference(temp2); |
| 2788 | __ cmpw(Address(temp2, primitive_offset), Immediate(Primitive::kPrimNot)); |
| 2789 | __ j(kNotEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2790 | // Re-poison the heap reference to make the compare instruction below |
| 2791 | // compare two poisoned references. |
| 2792 | __ PoisonHeapReference(temp1); |
| 2793 | } |
| 2794 | |
| 2795 | // Note: if heap poisoning is on, we are comparing two poisoned references here. |
| 2796 | __ cmpl(temp1, Address(src, class_offset)); |
| 2797 | |
| 2798 | if (optimizations.GetDestinationIsTypedObjectArray()) { |
| 2799 | NearLabel do_copy; |
| 2800 | __ j(kEqual, &do_copy); |
| 2801 | __ MaybeUnpoisonHeapReference(temp1); |
| 2802 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2803 | __ movl(temp1, Address(temp1, component_offset)); |
| 2804 | __ MaybeUnpoisonHeapReference(temp1); |
| 2805 | __ cmpl(Address(temp1, super_offset), Immediate(0)); |
| 2806 | __ j(kNotEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2807 | __ Bind(&do_copy); |
| 2808 | } else { |
| 2809 | __ j(kNotEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2810 | } |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2811 | } |
| 2812 | } else if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 2813 | DCHECK(optimizations.GetDestinationIsNonPrimitiveArray()); |
| 2814 | // Bail out if the source is not a non primitive array. |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2815 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2816 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 2817 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2818 | invoke, temp1_loc, src, class_offset, /* needs_null_check= */ false); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2819 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2820 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2821 | invoke, temp1_loc, temp1, component_offset, /* needs_null_check= */ false); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2822 | __ testl(temp1, temp1); |
| 2823 | __ j(kEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2824 | // If heap poisoning is enabled, `temp1` has been unpoisoned |
| 2825 | // by the the previous call to GenerateFieldLoadWithBakerReadBarrier. |
| 2826 | } else { |
| 2827 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 2828 | __ movl(temp1, Address(src, class_offset)); |
| 2829 | __ MaybeUnpoisonHeapReference(temp1); |
| 2830 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2831 | __ movl(temp1, Address(temp1, component_offset)); |
| 2832 | __ testl(temp1, temp1); |
| 2833 | __ j(kEqual, intrinsic_slow_path->GetEntryLabel()); |
| 2834 | __ MaybeUnpoisonHeapReference(temp1); |
| 2835 | } |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2836 | __ cmpw(Address(temp1, primitive_offset), Immediate(Primitive::kPrimNot)); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2837 | __ j(kNotEqual, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2838 | } |
| 2839 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2840 | const DataType::Type type = DataType::Type::kReference; |
| 2841 | const int32_t element_size = DataType::Size(type); |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2842 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2843 | // Compute the base source address in `temp1`. |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2844 | GenSystemArrayCopyBaseAddress(GetAssembler(), type, src, src_pos, temp1); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2845 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2846 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2847 | // If it is needed (in the case of the fast-path loop), the base |
| 2848 | // destination address is computed later, as `temp2` is used for |
| 2849 | // intermediate computations. |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2850 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2851 | // Compute the end source address in `temp3`. |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2852 | if (length.IsStackSlot()) { |
| 2853 | // Location `length` is again pointing at a stack slot, as |
| 2854 | // register `temp3` (which was containing the length parameter |
| 2855 | // earlier) has been overwritten; restore it now |
| 2856 | DCHECK(length.Equals(length_arg)); |
| 2857 | __ movl(temp3, Address(ESP, length.GetStackIndex())); |
| 2858 | length = Location::RegisterLocation(temp3); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2859 | } |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2860 | GenSystemArrayCopyEndAddress(GetAssembler(), type, length, temp1, temp3); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2861 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2862 | // SystemArrayCopy implementation for Baker read barriers (see |
| 2863 | // also CodeGeneratorX86::GenerateReferenceLoadWithBakerReadBarrier): |
| 2864 | // |
| 2865 | // if (src_ptr != end_ptr) { |
| 2866 | // uint32_t rb_state = Lockword(src->monitor_).ReadBarrierState(); |
| 2867 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 2868 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2869 | // if (is_gray) { |
| 2870 | // // Slow-path copy. |
| 2871 | // for (size_t i = 0; i != length; ++i) { |
| 2872 | // dest_array[dest_pos + i] = |
| 2873 | // MaybePoison(ReadBarrier::Mark(MaybeUnpoison(src_array[src_pos + i]))); |
| 2874 | // } |
| 2875 | // } else { |
| 2876 | // // Fast-path copy. |
| 2877 | // do { |
| 2878 | // *dest_ptr++ = *src_ptr++; |
| 2879 | // } while (src_ptr != end_ptr) |
| 2880 | // } |
| 2881 | // } |
| 2882 | |
| 2883 | NearLabel loop, done; |
| 2884 | |
| 2885 | // Don't enter copy loop if `length == 0`. |
| 2886 | __ cmpl(temp1, temp3); |
| 2887 | __ j(kEqual, &done); |
| 2888 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 2889 | // 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] | 2890 | static_assert(ReadBarrier::NonGrayState() == 0, "Expecting non-gray to have value 0"); |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 2891 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 2892 | constexpr uint32_t gray_byte_position = LockWord::kReadBarrierStateShift / kBitsPerByte; |
| 2893 | constexpr uint32_t gray_bit_position = LockWord::kReadBarrierStateShift % kBitsPerByte; |
| 2894 | constexpr int32_t test_value = static_cast<int8_t>(1 << gray_bit_position); |
| 2895 | |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 2896 | // if (rb_state == ReadBarrier::GrayState()) |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 2897 | // goto slow_path; |
| 2898 | // At this point, just do the "if" and make sure that flags are preserved until the branch. |
| 2899 | __ testb(Address(src, monitor_offset + gray_byte_position), Immediate(test_value)); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2900 | |
| 2901 | // Load fence to prevent load-load reordering. |
| 2902 | // Note that this is a no-op, thanks to the x86 memory model. |
| 2903 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kLoadAny); |
| 2904 | |
| 2905 | // Slow path used to copy array when `src` is gray. |
| 2906 | SlowPathCode* read_barrier_slow_path = |
Vladimir Marko | 174b2e2 | 2017-10-12 13:34:49 +0100 | [diff] [blame] | 2907 | new (codegen_->GetScopedAllocator()) ReadBarrierSystemArrayCopySlowPathX86(invoke); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2908 | codegen_->AddSlowPath(read_barrier_slow_path); |
| 2909 | |
Vladimir Marko | 953437b | 2016-08-24 08:30:46 +0000 | [diff] [blame] | 2910 | // We have done the "if" of the gray bit check above, now branch based on the flags. |
| 2911 | __ j(kNotZero, read_barrier_slow_path->GetEntryLabel()); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2912 | |
| 2913 | // Fast-path copy. |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2914 | // Compute the base destination address in `temp2`. |
| 2915 | GenSystemArrayCopyBaseAddress(GetAssembler(), type, dest, dest_pos, temp2); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2916 | // Iterate over the arrays and do a raw copy of the objects. We don't need to |
| 2917 | // poison/unpoison. |
| 2918 | __ Bind(&loop); |
| 2919 | __ pushl(Address(temp1, 0)); |
| 2920 | __ cfi().AdjustCFAOffset(4); |
| 2921 | __ popl(Address(temp2, 0)); |
| 2922 | __ cfi().AdjustCFAOffset(-4); |
| 2923 | __ addl(temp1, Immediate(element_size)); |
| 2924 | __ addl(temp2, Immediate(element_size)); |
| 2925 | __ cmpl(temp1, temp3); |
| 2926 | __ j(kNotEqual, &loop); |
| 2927 | |
| 2928 | __ Bind(read_barrier_slow_path->GetExitLabel()); |
| 2929 | __ Bind(&done); |
| 2930 | } else { |
| 2931 | // Non read barrier code. |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2932 | // Compute the base destination address in `temp2`. |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2933 | GenSystemArrayCopyBaseAddress(GetAssembler(), type, dest, dest_pos, temp2); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2934 | // Compute the end source address in `temp3`. |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 2935 | GenSystemArrayCopyEndAddress(GetAssembler(), type, length, temp1, temp3); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2936 | // Iterate over the arrays and do a raw copy of the objects. We don't need to |
| 2937 | // poison/unpoison. |
| 2938 | NearLabel loop, done; |
| 2939 | __ cmpl(temp1, temp3); |
| 2940 | __ j(kEqual, &done); |
| 2941 | __ Bind(&loop); |
| 2942 | __ pushl(Address(temp1, 0)); |
| 2943 | __ cfi().AdjustCFAOffset(4); |
| 2944 | __ popl(Address(temp2, 0)); |
| 2945 | __ cfi().AdjustCFAOffset(-4); |
| 2946 | __ addl(temp1, Immediate(element_size)); |
| 2947 | __ addl(temp2, Immediate(element_size)); |
| 2948 | __ cmpl(temp1, temp3); |
| 2949 | __ j(kNotEqual, &loop); |
| 2950 | __ Bind(&done); |
| 2951 | } |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2952 | |
| 2953 | // We only need one card marking on the destination array. |
Andreas Gampe | 3db7068 | 2018-12-26 15:12:03 -0800 | [diff] [blame] | 2954 | codegen_->MarkGCCard(temp1, temp2, dest, Register(kNoRegister), /* value_can_be_null= */ false); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2955 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2956 | __ Bind(intrinsic_slow_path->GetExitLabel()); |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2957 | } |
| 2958 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2959 | void IntrinsicLocationsBuilderX86::VisitIntegerValueOf(HInvoke* invoke) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2960 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2961 | InvokeRuntimeCallingConvention calling_convention; |
| 2962 | IntrinsicVisitor::ComputeIntegerValueOfLocations( |
| 2963 | invoke, |
| 2964 | codegen_, |
| 2965 | Location::RegisterLocation(EAX), |
| 2966 | Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2967 | |
| 2968 | LocationSummary* locations = invoke->GetLocations(); |
| 2969 | if (locations != nullptr) { |
| 2970 | HInvokeStaticOrDirect* invoke_static_or_direct = invoke->AsInvokeStaticOrDirect(); |
| 2971 | if (invoke_static_or_direct->HasSpecialInput() && |
| 2972 | invoke->InputAt(invoke_static_or_direct->GetSpecialInputIndex()) |
| 2973 | ->IsX86ComputeBaseMethodAddress()) { |
| 2974 | locations->SetInAt(invoke_static_or_direct->GetSpecialInputIndex(), |
| 2975 | Location::RequiresRegister()); |
| 2976 | } |
| 2977 | } |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | void IntrinsicCodeGeneratorX86::VisitIntegerValueOf(HInvoke* invoke) { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2981 | DCHECK(invoke->IsInvokeStaticOrDirect()); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 2982 | IntrinsicVisitor::IntegerValueOfInfo info = |
| 2983 | IntrinsicVisitor::ComputeIntegerValueOfInfo(invoke, codegen_->GetCompilerOptions()); |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2984 | LocationSummary* locations = invoke->GetLocations(); |
| 2985 | X86Assembler* assembler = GetAssembler(); |
| 2986 | |
| 2987 | Register out = locations->Out().AsRegister<Register>(); |
| 2988 | InvokeRuntimeCallingConvention calling_convention; |
| 2989 | if (invoke->InputAt(0)->IsConstant()) { |
| 2990 | int32_t value = invoke->InputAt(0)->AsIntConstant()->GetValue(); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 2991 | if (static_cast<uint32_t>(value - info.low) < info.length) { |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2992 | // Just embed the j.l.Integer in the code. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 2993 | DCHECK_NE(info.value_boot_image_reference, IntegerValueOfInfo::kInvalidReference); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2994 | codegen_->LoadBootImageAddress( |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 2995 | out, info.value_boot_image_reference, invoke->AsInvokeStaticOrDirect()); |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2996 | } else { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 2997 | DCHECK(locations->CanCall()); |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2998 | // Allocate and initialize a new j.l.Integer. |
| 2999 | // TODO: If we JIT, we could allocate the j.l.Integer now, and store it in the |
| 3000 | // JIT object table. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 3001 | codegen_->AllocateInstanceForIntrinsic(invoke->AsInvokeStaticOrDirect(), |
| 3002 | info.integer_boot_image_offset); |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 3003 | __ movl(Address(out, info.value_offset), Immediate(value)); |
| 3004 | } |
| 3005 | } else { |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 3006 | DCHECK(locations->CanCall()); |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 3007 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 3008 | // Check bounds of our cache. |
| 3009 | __ leal(out, Address(in, -info.low)); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 3010 | __ cmpl(out, Immediate(info.length)); |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 3011 | NearLabel allocate, done; |
| 3012 | __ j(kAboveEqual, &allocate); |
| 3013 | // If the value is within the bounds, load the j.l.Integer directly from the array. |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 3014 | constexpr size_t kElementSize = sizeof(mirror::HeapReference<mirror::Object>); |
Vladimir Marko | eebb821 | 2018-06-05 14:57:24 +0100 | [diff] [blame] | 3015 | static_assert((1u << TIMES_4) == sizeof(mirror::HeapReference<mirror::Object>), |
| 3016 | "Check heap reference size."); |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 3017 | if (codegen_->GetCompilerOptions().IsBootImage()) { |
| 3018 | DCHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u); |
| 3019 | size_t method_address_index = invoke->AsInvokeStaticOrDirect()->GetSpecialInputIndex(); |
| 3020 | HX86ComputeBaseMethodAddress* method_address = |
| 3021 | invoke->InputAt(method_address_index)->AsX86ComputeBaseMethodAddress(); |
| 3022 | DCHECK(method_address != nullptr); |
| 3023 | Register method_address_reg = |
| 3024 | invoke->GetLocations()->InAt(method_address_index).AsRegister<Register>(); |
| 3025 | __ movl(out, Address(method_address_reg, out, TIMES_4, CodeGeneratorX86::kDummy32BitOffset)); |
| 3026 | codegen_->RecordBootImageIntrinsicPatch(method_address, info.array_data_boot_image_reference); |
| 3027 | } else { |
| 3028 | // Note: We're about to clobber the index in `out`, so we need to use `in` and |
| 3029 | // adjust the offset accordingly. |
| 3030 | uint32_t mid_array_boot_image_offset = |
| 3031 | info.array_data_boot_image_reference - info.low * kElementSize; |
| 3032 | codegen_->LoadBootImageAddress( |
| 3033 | out, mid_array_boot_image_offset, invoke->AsInvokeStaticOrDirect()); |
| 3034 | DCHECK_NE(out, in); |
| 3035 | __ movl(out, Address(out, in, TIMES_4, 0)); |
| 3036 | } |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 3037 | __ MaybeUnpoisonHeapReference(out); |
| 3038 | __ jmp(&done); |
| 3039 | __ Bind(&allocate); |
| 3040 | // Otherwise allocate and initialize a new j.l.Integer. |
Vladimir Marko | 6fd1606 | 2018-06-26 11:02:04 +0100 | [diff] [blame] | 3041 | codegen_->AllocateInstanceForIntrinsic(invoke->AsInvokeStaticOrDirect(), |
| 3042 | info.integer_boot_image_offset); |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 3043 | __ movl(Address(out, info.value_offset), in); |
| 3044 | __ Bind(&done); |
| 3045 | } |
| 3046 | } |
| 3047 | |
Nicolas Geoffray | 365719c | 2017-03-08 13:11:50 +0000 | [diff] [blame] | 3048 | void IntrinsicLocationsBuilderX86::VisitThreadInterrupted(HInvoke* invoke) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 3049 | LocationSummary* locations = |
| 3050 | new (allocator_) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
Nicolas Geoffray | 365719c | 2017-03-08 13:11:50 +0000 | [diff] [blame] | 3051 | locations->SetOut(Location::RequiresRegister()); |
| 3052 | } |
| 3053 | |
| 3054 | void IntrinsicCodeGeneratorX86::VisitThreadInterrupted(HInvoke* invoke) { |
| 3055 | X86Assembler* assembler = GetAssembler(); |
| 3056 | Register out = invoke->GetLocations()->Out().AsRegister<Register>(); |
| 3057 | Address address = Address::Absolute(Thread::InterruptedOffset<kX86PointerSize>().Int32Value()); |
| 3058 | NearLabel done; |
| 3059 | __ fs()->movl(out, address); |
| 3060 | __ testl(out, out); |
| 3061 | __ j(kEqual, &done); |
| 3062 | __ fs()->movl(address, Immediate(0)); |
| 3063 | codegen_->MemoryFence(); |
| 3064 | __ Bind(&done); |
| 3065 | } |
| 3066 | |
Hans Boehm | c7b28de | 2018-03-09 17:05:28 -0800 | [diff] [blame] | 3067 | void IntrinsicLocationsBuilderX86::VisitReachabilityFence(HInvoke* invoke) { |
| 3068 | LocationSummary* locations = |
| 3069 | new (allocator_) LocationSummary(invoke, LocationSummary::kNoCall, kIntrinsified); |
| 3070 | locations->SetInAt(0, Location::Any()); |
| 3071 | } |
| 3072 | |
| 3073 | void IntrinsicCodeGeneratorX86::VisitReachabilityFence(HInvoke* invoke ATTRIBUTE_UNUSED) { } |
Nicolas Geoffray | 365719c | 2017-03-08 13:11:50 +0000 | [diff] [blame] | 3074 | |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 3075 | UNIMPLEMENTED_INTRINSIC(X86, MathRoundDouble) |
Vladimir Marko | 4ee8e29 | 2017-06-02 15:39:30 +0000 | [diff] [blame] | 3076 | UNIMPLEMENTED_INTRINSIC(X86, ReferenceGetReferent) |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 3077 | UNIMPLEMENTED_INTRINSIC(X86, FloatIsInfinite) |
| 3078 | UNIMPLEMENTED_INTRINSIC(X86, DoubleIsInfinite) |
| 3079 | UNIMPLEMENTED_INTRINSIC(X86, IntegerHighestOneBit) |
| 3080 | UNIMPLEMENTED_INTRINSIC(X86, LongHighestOneBit) |
xueliang.zhong | cb58b07 | 2017-10-13 12:06:56 +0100 | [diff] [blame] | 3081 | UNIMPLEMENTED_INTRINSIC(X86, CRC32Update) |
Evgeny Astigeevich | 15c5b97 | 2018-11-20 13:41:40 +0000 | [diff] [blame] | 3082 | UNIMPLEMENTED_INTRINSIC(X86, CRC32UpdateBytes) |
Evgeny Astigeevich | 776a7c2 | 2018-12-17 11:40:34 +0000 | [diff] [blame] | 3083 | UNIMPLEMENTED_INTRINSIC(X86, CRC32UpdateByteBuffer) |
xueliang.zhong | 9ce340f | 2019-01-22 17:46:09 +0000 | [diff] [blame] | 3084 | UNIMPLEMENTED_INTRINSIC(X86, FP16ToFloat) |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3085 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3086 | UNIMPLEMENTED_INTRINSIC(X86, StringStringIndexOf); |
| 3087 | UNIMPLEMENTED_INTRINSIC(X86, StringStringIndexOfAfter); |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 3088 | UNIMPLEMENTED_INTRINSIC(X86, StringBufferAppend); |
| 3089 | UNIMPLEMENTED_INTRINSIC(X86, StringBufferLength); |
| 3090 | UNIMPLEMENTED_INTRINSIC(X86, StringBufferToString); |
Vladimir Marko | d456117 | 2017-10-30 17:48:25 +0000 | [diff] [blame] | 3091 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendObject); |
| 3092 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendString); |
| 3093 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendCharSequence); |
| 3094 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendCharArray); |
| 3095 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendBoolean); |
| 3096 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendChar); |
| 3097 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendInt); |
| 3098 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendLong); |
| 3099 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendFloat); |
| 3100 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderAppendDouble); |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 3101 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderLength); |
| 3102 | UNIMPLEMENTED_INTRINSIC(X86, StringBuilderToString); |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3103 | |
Aart Bik | 0e54c01 | 2016-03-04 12:08:31 -0800 | [diff] [blame] | 3104 | // 1.8. |
| 3105 | UNIMPLEMENTED_INTRINSIC(X86, UnsafeGetAndAddInt) |
| 3106 | UNIMPLEMENTED_INTRINSIC(X86, UnsafeGetAndAddLong) |
| 3107 | UNIMPLEMENTED_INTRINSIC(X86, UnsafeGetAndSetInt) |
| 3108 | UNIMPLEMENTED_INTRINSIC(X86, UnsafeGetAndSetLong) |
| 3109 | UNIMPLEMENTED_INTRINSIC(X86, UnsafeGetAndSetObject) |
Aart Bik | 0e54c01 | 2016-03-04 12:08:31 -0800 | [diff] [blame] | 3110 | |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 3111 | UNREACHABLE_INTRINSICS(X86) |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 3112 | |
| 3113 | #undef __ |
| 3114 | |
Mark Mendell | 09ed1a3 | 2015-03-25 08:30:06 -0400 | [diff] [blame] | 3115 | } // namespace x86 |
| 3116 | } // namespace art |