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