| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "code_generator_arm64.h" |
| 18 | #include "mirror/array-inl.h" |
| 19 | |
| 20 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
| 21 | |
| 22 | namespace art { |
| 23 | namespace arm64 { |
| 24 | |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 25 | using helpers::VRegisterFrom; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 26 | using helpers::HeapOperand; |
| 27 | using helpers::InputRegisterAt; |
| 28 | using helpers::Int64ConstantFrom; |
| 29 | using helpers::XRegisterFrom; |
| 30 | |
| 31 | #define __ GetVIXLAssembler()-> |
| 32 | |
| 33 | void LocationsBuilderARM64::VisitVecReplicateScalar(HVecReplicateScalar* instruction) { |
| 34 | LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction); |
| 35 | switch (instruction->GetPackedType()) { |
| 36 | case Primitive::kPrimBoolean: |
| 37 | case Primitive::kPrimByte: |
| 38 | case Primitive::kPrimChar: |
| 39 | case Primitive::kPrimShort: |
| 40 | case Primitive::kPrimInt: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 41 | case Primitive::kPrimLong: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 42 | locations->SetInAt(0, Location::RequiresRegister()); |
| 43 | locations->SetOut(Location::RequiresFpuRegister()); |
| 44 | break; |
| 45 | case Primitive::kPrimFloat: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 46 | case Primitive::kPrimDouble: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 47 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 48 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 49 | break; |
| 50 | default: |
| 51 | LOG(FATAL) << "Unsupported SIMD type"; |
| 52 | UNREACHABLE(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | void InstructionCodeGeneratorARM64::VisitVecReplicateScalar(HVecReplicateScalar* instruction) { |
| 57 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 58 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 59 | switch (instruction->GetPackedType()) { |
| 60 | case Primitive::kPrimBoolean: |
| 61 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 62 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 63 | __ Dup(dst.V16B(), InputRegisterAt(instruction, 0)); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 64 | break; |
| 65 | case Primitive::kPrimChar: |
| 66 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 67 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 68 | __ Dup(dst.V8H(), InputRegisterAt(instruction, 0)); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 69 | break; |
| 70 | case Primitive::kPrimInt: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 71 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 72 | __ Dup(dst.V4S(), InputRegisterAt(instruction, 0)); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 73 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 74 | case Primitive::kPrimLong: |
| 75 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 76 | __ Dup(dst.V2D(), XRegisterFrom(locations->InAt(0))); |
| 77 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 78 | case Primitive::kPrimFloat: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 79 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 80 | __ Dup(dst.V4S(), VRegisterFrom(locations->InAt(0)).V4S(), 0); |
| 81 | break; |
| 82 | case Primitive::kPrimDouble: |
| 83 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 84 | __ Dup(dst.V2D(), VRegisterFrom(locations->InAt(0)).V2D(), 0); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 85 | break; |
| 86 | default: |
| 87 | LOG(FATAL) << "Unsupported SIMD type"; |
| 88 | UNREACHABLE(); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | void LocationsBuilderARM64::VisitVecSetScalars(HVecSetScalars* instruction) { |
| 93 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 94 | } |
| 95 | |
| 96 | void InstructionCodeGeneratorARM64::VisitVecSetScalars(HVecSetScalars* instruction) { |
| 97 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 98 | } |
| 99 | |
| 100 | void LocationsBuilderARM64::VisitVecSumReduce(HVecSumReduce* instruction) { |
| 101 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 102 | } |
| 103 | |
| 104 | void InstructionCodeGeneratorARM64::VisitVecSumReduce(HVecSumReduce* instruction) { |
| 105 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 106 | } |
| 107 | |
| 108 | // Helper to set up locations for vector unary operations. |
| 109 | static void CreateVecUnOpLocations(ArenaAllocator* arena, HVecUnaryOperation* instruction) { |
| 110 | LocationSummary* locations = new (arena) LocationSummary(instruction); |
| 111 | switch (instruction->GetPackedType()) { |
| 112 | case Primitive::kPrimBoolean: |
| 113 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 114 | locations->SetOut(Location::RequiresFpuRegister(), |
| 115 | instruction->IsVecNot() ? Location::kOutputOverlap |
| 116 | : Location::kNoOutputOverlap); |
| 117 | break; |
| 118 | case Primitive::kPrimByte: |
| 119 | case Primitive::kPrimChar: |
| 120 | case Primitive::kPrimShort: |
| 121 | case Primitive::kPrimInt: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 122 | case Primitive::kPrimLong: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 123 | case Primitive::kPrimFloat: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 124 | case Primitive::kPrimDouble: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 125 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 126 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 127 | break; |
| 128 | default: |
| 129 | LOG(FATAL) << "Unsupported SIMD type"; |
| 130 | UNREACHABLE(); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void LocationsBuilderARM64::VisitVecCnv(HVecCnv* instruction) { |
| 135 | CreateVecUnOpLocations(GetGraph()->GetArena(), instruction); |
| 136 | } |
| 137 | |
| 138 | void InstructionCodeGeneratorARM64::VisitVecCnv(HVecCnv* instruction) { |
| 139 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 140 | VRegister src = VRegisterFrom(locations->InAt(0)); |
| 141 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 142 | Primitive::Type from = instruction->GetInputType(); |
| 143 | Primitive::Type to = instruction->GetResultType(); |
| 144 | if (from == Primitive::kPrimInt && to == Primitive::kPrimFloat) { |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 145 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 146 | __ Scvtf(dst.V4S(), src.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 147 | } else { |
| 148 | LOG(FATAL) << "Unsupported SIMD type"; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void LocationsBuilderARM64::VisitVecNeg(HVecNeg* instruction) { |
| 153 | CreateVecUnOpLocations(GetGraph()->GetArena(), instruction); |
| 154 | } |
| 155 | |
| 156 | void InstructionCodeGeneratorARM64::VisitVecNeg(HVecNeg* instruction) { |
| 157 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 158 | VRegister src = VRegisterFrom(locations->InAt(0)); |
| 159 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 160 | switch (instruction->GetPackedType()) { |
| 161 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 162 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 163 | __ Neg(dst.V16B(), src.V16B()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 164 | break; |
| 165 | case Primitive::kPrimChar: |
| 166 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 167 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 168 | __ Neg(dst.V8H(), src.V8H()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 169 | break; |
| 170 | case Primitive::kPrimInt: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 171 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 172 | __ Neg(dst.V4S(), src.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 173 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 174 | case Primitive::kPrimLong: |
| 175 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 176 | __ Neg(dst.V2D(), src.V2D()); |
| 177 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 178 | case Primitive::kPrimFloat: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 179 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 180 | __ Fneg(dst.V4S(), src.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 181 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 182 | case Primitive::kPrimDouble: |
| 183 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 184 | __ Fneg(dst.V2D(), src.V2D()); |
| 185 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 186 | default: |
| 187 | LOG(FATAL) << "Unsupported SIMD type"; |
| 188 | UNREACHABLE(); |
| 189 | } |
| 190 | } |
| 191 | |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 192 | void LocationsBuilderARM64::VisitVecAbs(HVecAbs* instruction) { |
| 193 | CreateVecUnOpLocations(GetGraph()->GetArena(), instruction); |
| 194 | } |
| 195 | |
| 196 | void InstructionCodeGeneratorARM64::VisitVecAbs(HVecAbs* instruction) { |
| 197 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 198 | VRegister src = VRegisterFrom(locations->InAt(0)); |
| 199 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 200 | switch (instruction->GetPackedType()) { |
| 201 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 202 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 203 | __ Abs(dst.V16B(), src.V16B()); |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 204 | break; |
| 205 | case Primitive::kPrimChar: |
| 206 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 207 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 208 | __ Abs(dst.V8H(), src.V8H()); |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 209 | break; |
| 210 | case Primitive::kPrimInt: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 211 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 212 | __ Abs(dst.V4S(), src.V4S()); |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 213 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 214 | case Primitive::kPrimLong: |
| 215 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 216 | __ Abs(dst.V2D(), src.V2D()); |
| 217 | break; |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 218 | case Primitive::kPrimFloat: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 219 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 220 | __ Fabs(dst.V4S(), src.V4S()); |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 221 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 222 | case Primitive::kPrimDouble: |
| 223 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 224 | __ Fabs(dst.V2D(), src.V2D()); |
| 225 | break; |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 226 | default: |
| 227 | LOG(FATAL) << "Unsupported SIMD type"; |
| 228 | } |
| 229 | } |
| 230 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 231 | void LocationsBuilderARM64::VisitVecNot(HVecNot* instruction) { |
| 232 | CreateVecUnOpLocations(GetGraph()->GetArena(), instruction); |
| 233 | } |
| 234 | |
| 235 | void InstructionCodeGeneratorARM64::VisitVecNot(HVecNot* instruction) { |
| 236 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 237 | VRegister src = VRegisterFrom(locations->InAt(0)); |
| 238 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 239 | switch (instruction->GetPackedType()) { |
| 240 | case Primitive::kPrimBoolean: // special case boolean-not |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 241 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 242 | __ Movi(dst.V16B(), 1); |
| 243 | __ Eor(dst.V16B(), dst.V16B(), src.V16B()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 244 | break; |
| 245 | case Primitive::kPrimByte: |
| 246 | case Primitive::kPrimChar: |
| 247 | case Primitive::kPrimShort: |
| 248 | case Primitive::kPrimInt: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 249 | case Primitive::kPrimLong: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 250 | __ Not(dst.V16B(), src.V16B()); // lanes do not matter |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 251 | break; |
| 252 | default: |
| 253 | LOG(FATAL) << "Unsupported SIMD type"; |
| 254 | UNREACHABLE(); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // Helper to set up locations for vector binary operations. |
| 259 | static void CreateVecBinOpLocations(ArenaAllocator* arena, HVecBinaryOperation* instruction) { |
| 260 | LocationSummary* locations = new (arena) LocationSummary(instruction); |
| 261 | switch (instruction->GetPackedType()) { |
| 262 | case Primitive::kPrimBoolean: |
| 263 | case Primitive::kPrimByte: |
| 264 | case Primitive::kPrimChar: |
| 265 | case Primitive::kPrimShort: |
| 266 | case Primitive::kPrimInt: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 267 | case Primitive::kPrimLong: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 268 | case Primitive::kPrimFloat: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 269 | case Primitive::kPrimDouble: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 270 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 271 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 272 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 273 | break; |
| 274 | default: |
| 275 | LOG(FATAL) << "Unsupported SIMD type"; |
| 276 | UNREACHABLE(); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | void LocationsBuilderARM64::VisitVecAdd(HVecAdd* instruction) { |
| 281 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 282 | } |
| 283 | |
| 284 | void InstructionCodeGeneratorARM64::VisitVecAdd(HVecAdd* instruction) { |
| 285 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 286 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 287 | VRegister rhs = VRegisterFrom(locations->InAt(1)); |
| 288 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 289 | switch (instruction->GetPackedType()) { |
| 290 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 291 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 292 | __ Add(dst.V16B(), lhs.V16B(), rhs.V16B()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 293 | break; |
| 294 | case Primitive::kPrimChar: |
| 295 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 296 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 297 | __ Add(dst.V8H(), lhs.V8H(), rhs.V8H()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 298 | break; |
| 299 | case Primitive::kPrimInt: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 300 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 301 | __ Add(dst.V4S(), lhs.V4S(), rhs.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 302 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 303 | case Primitive::kPrimLong: |
| 304 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 305 | __ Add(dst.V2D(), lhs.V2D(), rhs.V2D()); |
| 306 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 307 | case Primitive::kPrimFloat: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 308 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 309 | __ Fadd(dst.V4S(), lhs.V4S(), rhs.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 310 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 311 | case Primitive::kPrimDouble: |
| 312 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 313 | __ Fadd(dst.V2D(), lhs.V2D(), rhs.V2D()); |
| 314 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 315 | default: |
| 316 | LOG(FATAL) << "Unsupported SIMD type"; |
| 317 | UNREACHABLE(); |
| 318 | } |
| 319 | } |
| 320 | |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame^] | 321 | void LocationsBuilderARM64::VisitVecHalvingAdd(HVecHalvingAdd* instruction) { |
| 322 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 323 | } |
| 324 | |
| 325 | void InstructionCodeGeneratorARM64::VisitVecHalvingAdd(HVecHalvingAdd* instruction) { |
| 326 | LocationSummary* locations = instruction->GetLocations(); |
| 327 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 328 | VRegister rhs = VRegisterFrom(locations->InAt(1)); |
| 329 | VRegister dst = VRegisterFrom(locations->Out()); |
| 330 | switch (instruction->GetPackedType()) { |
| 331 | case Primitive::kPrimByte: |
| 332 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 333 | if (instruction->IsUnsigned()) { |
| 334 | instruction->IsRounded() |
| 335 | ? __ Urhadd(dst.V16B(), lhs.V16B(), rhs.V16B()) |
| 336 | : __ Uhadd(dst.V16B(), lhs.V16B(), rhs.V16B()); |
| 337 | } else { |
| 338 | instruction->IsRounded() |
| 339 | ? __ Srhadd(dst.V16B(), lhs.V16B(), rhs.V16B()) |
| 340 | : __ Shadd(dst.V16B(), lhs.V16B(), rhs.V16B()); |
| 341 | } |
| 342 | break; |
| 343 | case Primitive::kPrimChar: |
| 344 | case Primitive::kPrimShort: |
| 345 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 346 | if (instruction->IsUnsigned()) { |
| 347 | instruction->IsRounded() |
| 348 | ? __ Urhadd(dst.V8H(), lhs.V8H(), rhs.V8H()) |
| 349 | : __ Uhadd(dst.V8H(), lhs.V8H(), rhs.V8H()); |
| 350 | } else { |
| 351 | instruction->IsRounded() |
| 352 | ? __ Srhadd(dst.V8H(), lhs.V8H(), rhs.V8H()) |
| 353 | : __ Shadd(dst.V8H(), lhs.V8H(), rhs.V8H()); |
| 354 | } |
| 355 | break; |
| 356 | default: |
| 357 | LOG(FATAL) << "Unsupported SIMD type"; |
| 358 | UNREACHABLE(); |
| 359 | } |
| 360 | } |
| 361 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 362 | void LocationsBuilderARM64::VisitVecSub(HVecSub* instruction) { |
| 363 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 364 | } |
| 365 | |
| 366 | void InstructionCodeGeneratorARM64::VisitVecSub(HVecSub* instruction) { |
| 367 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 368 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 369 | VRegister rhs = VRegisterFrom(locations->InAt(1)); |
| 370 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 371 | switch (instruction->GetPackedType()) { |
| 372 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 373 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 374 | __ Sub(dst.V16B(), lhs.V16B(), rhs.V16B()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 375 | break; |
| 376 | case Primitive::kPrimChar: |
| 377 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 378 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 379 | __ Sub(dst.V8H(), lhs.V8H(), rhs.V8H()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 380 | break; |
| 381 | case Primitive::kPrimInt: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 382 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 383 | __ Sub(dst.V4S(), lhs.V4S(), rhs.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 384 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 385 | case Primitive::kPrimLong: |
| 386 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 387 | __ Sub(dst.V2D(), lhs.V2D(), rhs.V2D()); |
| 388 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 389 | case Primitive::kPrimFloat: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 390 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 391 | __ Fsub(dst.V4S(), lhs.V4S(), rhs.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 392 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 393 | case Primitive::kPrimDouble: |
| 394 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 395 | __ Fsub(dst.V2D(), lhs.V2D(), rhs.V2D()); |
| 396 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 397 | default: |
| 398 | LOG(FATAL) << "Unsupported SIMD type"; |
| 399 | UNREACHABLE(); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | void LocationsBuilderARM64::VisitVecMul(HVecMul* instruction) { |
| 404 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 405 | } |
| 406 | |
| 407 | void InstructionCodeGeneratorARM64::VisitVecMul(HVecMul* instruction) { |
| 408 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 409 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 410 | VRegister rhs = VRegisterFrom(locations->InAt(1)); |
| 411 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 412 | switch (instruction->GetPackedType()) { |
| 413 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 414 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 415 | __ Mul(dst.V16B(), lhs.V16B(), rhs.V16B()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 416 | break; |
| 417 | case Primitive::kPrimChar: |
| 418 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 419 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 420 | __ Mul(dst.V8H(), lhs.V8H(), rhs.V8H()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 421 | break; |
| 422 | case Primitive::kPrimInt: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 423 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 424 | __ Mul(dst.V4S(), lhs.V4S(), rhs.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 425 | break; |
| 426 | case Primitive::kPrimFloat: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 427 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 428 | __ Fmul(dst.V4S(), lhs.V4S(), rhs.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 429 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 430 | case Primitive::kPrimDouble: |
| 431 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 432 | __ Fmul(dst.V2D(), lhs.V2D(), rhs.V2D()); |
| 433 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 434 | default: |
| 435 | LOG(FATAL) << "Unsupported SIMD type"; |
| 436 | UNREACHABLE(); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | void LocationsBuilderARM64::VisitVecDiv(HVecDiv* instruction) { |
| 441 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 442 | } |
| 443 | |
| 444 | void InstructionCodeGeneratorARM64::VisitVecDiv(HVecDiv* instruction) { |
| 445 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 446 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 447 | VRegister rhs = VRegisterFrom(locations->InAt(1)); |
| 448 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 449 | switch (instruction->GetPackedType()) { |
| 450 | case Primitive::kPrimFloat: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 451 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 452 | __ Fdiv(dst.V4S(), lhs.V4S(), rhs.V4S()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 453 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 454 | case Primitive::kPrimDouble: |
| 455 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 456 | __ Fdiv(dst.V2D(), lhs.V2D(), rhs.V2D()); |
| 457 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 458 | default: |
| 459 | LOG(FATAL) << "Unsupported SIMD type"; |
| 460 | UNREACHABLE(); |
| 461 | } |
| 462 | } |
| 463 | |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame^] | 464 | void LocationsBuilderARM64::VisitVecMin(HVecMin* instruction) { |
| 465 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 466 | } |
| 467 | |
| 468 | void InstructionCodeGeneratorARM64::VisitVecMin(HVecMin* instruction) { |
| 469 | LOG(FATAL) << "Unsupported SIMD instruction " << instruction->GetId(); |
| 470 | } |
| 471 | |
| 472 | void LocationsBuilderARM64::VisitVecMax(HVecMax* instruction) { |
| 473 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 474 | } |
| 475 | |
| 476 | void InstructionCodeGeneratorARM64::VisitVecMax(HVecMax* instruction) { |
| 477 | LOG(FATAL) << "Unsupported SIMD instruction " << instruction->GetId(); |
| 478 | } |
| 479 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 480 | void LocationsBuilderARM64::VisitVecAnd(HVecAnd* instruction) { |
| 481 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 482 | } |
| 483 | |
| 484 | void InstructionCodeGeneratorARM64::VisitVecAnd(HVecAnd* instruction) { |
| 485 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 486 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 487 | VRegister rhs = VRegisterFrom(locations->InAt(1)); |
| 488 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 489 | switch (instruction->GetPackedType()) { |
| 490 | case Primitive::kPrimBoolean: |
| 491 | case Primitive::kPrimByte: |
| 492 | case Primitive::kPrimChar: |
| 493 | case Primitive::kPrimShort: |
| 494 | case Primitive::kPrimInt: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 495 | case Primitive::kPrimLong: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 496 | case Primitive::kPrimFloat: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 497 | case Primitive::kPrimDouble: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 498 | __ And(dst.V16B(), lhs.V16B(), rhs.V16B()); // lanes do not matter |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 499 | break; |
| 500 | default: |
| 501 | LOG(FATAL) << "Unsupported SIMD type"; |
| 502 | UNREACHABLE(); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | void LocationsBuilderARM64::VisitVecAndNot(HVecAndNot* instruction) { |
| 507 | LOG(FATAL) << "Unsupported SIMD instruction " << instruction->GetId(); |
| 508 | } |
| 509 | |
| 510 | void InstructionCodeGeneratorARM64::VisitVecAndNot(HVecAndNot* instruction) { |
| 511 | LOG(FATAL) << "Unsupported SIMD instruction " << instruction->GetId(); |
| 512 | } |
| 513 | |
| 514 | void LocationsBuilderARM64::VisitVecOr(HVecOr* instruction) { |
| 515 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 516 | } |
| 517 | |
| 518 | void InstructionCodeGeneratorARM64::VisitVecOr(HVecOr* instruction) { |
| 519 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 520 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 521 | VRegister rhs = VRegisterFrom(locations->InAt(1)); |
| 522 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 523 | switch (instruction->GetPackedType()) { |
| 524 | case Primitive::kPrimBoolean: |
| 525 | case Primitive::kPrimByte: |
| 526 | case Primitive::kPrimChar: |
| 527 | case Primitive::kPrimShort: |
| 528 | case Primitive::kPrimInt: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 529 | case Primitive::kPrimLong: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 530 | case Primitive::kPrimFloat: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 531 | case Primitive::kPrimDouble: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 532 | __ Orr(dst.V16B(), lhs.V16B(), rhs.V16B()); // lanes do not matter |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 533 | break; |
| 534 | default: |
| 535 | LOG(FATAL) << "Unsupported SIMD type"; |
| 536 | UNREACHABLE(); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | void LocationsBuilderARM64::VisitVecXor(HVecXor* instruction) { |
| 541 | CreateVecBinOpLocations(GetGraph()->GetArena(), instruction); |
| 542 | } |
| 543 | |
| 544 | void InstructionCodeGeneratorARM64::VisitVecXor(HVecXor* instruction) { |
| 545 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 546 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 547 | VRegister rhs = VRegisterFrom(locations->InAt(1)); |
| 548 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 549 | switch (instruction->GetPackedType()) { |
| 550 | case Primitive::kPrimBoolean: |
| 551 | case Primitive::kPrimByte: |
| 552 | case Primitive::kPrimChar: |
| 553 | case Primitive::kPrimShort: |
| 554 | case Primitive::kPrimInt: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 555 | case Primitive::kPrimLong: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 556 | case Primitive::kPrimFloat: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 557 | case Primitive::kPrimDouble: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 558 | __ Eor(dst.V16B(), lhs.V16B(), rhs.V16B()); // lanes do not matter |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 559 | break; |
| 560 | default: |
| 561 | LOG(FATAL) << "Unsupported SIMD type"; |
| 562 | UNREACHABLE(); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | // Helper to set up locations for vector shift operations. |
| 567 | static void CreateVecShiftLocations(ArenaAllocator* arena, HVecBinaryOperation* instruction) { |
| 568 | LocationSummary* locations = new (arena) LocationSummary(instruction); |
| 569 | switch (instruction->GetPackedType()) { |
| 570 | case Primitive::kPrimByte: |
| 571 | case Primitive::kPrimChar: |
| 572 | case Primitive::kPrimShort: |
| 573 | case Primitive::kPrimInt: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 574 | case Primitive::kPrimLong: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 575 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 576 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 577 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 578 | break; |
| 579 | default: |
| 580 | LOG(FATAL) << "Unsupported SIMD type"; |
| 581 | UNREACHABLE(); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | void LocationsBuilderARM64::VisitVecShl(HVecShl* instruction) { |
| 586 | CreateVecShiftLocations(GetGraph()->GetArena(), instruction); |
| 587 | } |
| 588 | |
| 589 | void InstructionCodeGeneratorARM64::VisitVecShl(HVecShl* instruction) { |
| 590 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 591 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 592 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 593 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 594 | switch (instruction->GetPackedType()) { |
| 595 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 596 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 597 | __ Shl(dst.V16B(), lhs.V16B(), value); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 598 | break; |
| 599 | case Primitive::kPrimChar: |
| 600 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 601 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 602 | __ Shl(dst.V8H(), lhs.V8H(), value); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 603 | break; |
| 604 | case Primitive::kPrimInt: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 605 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 606 | __ Shl(dst.V4S(), lhs.V4S(), value); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 607 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 608 | case Primitive::kPrimLong: |
| 609 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 610 | __ Shl(dst.V2D(), lhs.V2D(), value); |
| 611 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 612 | default: |
| 613 | LOG(FATAL) << "Unsupported SIMD type"; |
| 614 | UNREACHABLE(); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | void LocationsBuilderARM64::VisitVecShr(HVecShr* instruction) { |
| 619 | CreateVecShiftLocations(GetGraph()->GetArena(), instruction); |
| 620 | } |
| 621 | |
| 622 | void InstructionCodeGeneratorARM64::VisitVecShr(HVecShr* instruction) { |
| 623 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 624 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 625 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 626 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 627 | switch (instruction->GetPackedType()) { |
| 628 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 629 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 630 | __ Sshr(dst.V16B(), lhs.V16B(), value); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 631 | break; |
| 632 | case Primitive::kPrimChar: |
| 633 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 634 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 635 | __ Sshr(dst.V8H(), lhs.V8H(), value); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 636 | break; |
| 637 | case Primitive::kPrimInt: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 638 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 639 | __ Sshr(dst.V4S(), lhs.V4S(), value); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 640 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 641 | case Primitive::kPrimLong: |
| 642 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 643 | __ Sshr(dst.V2D(), lhs.V2D(), value); |
| 644 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 645 | default: |
| 646 | LOG(FATAL) << "Unsupported SIMD type"; |
| 647 | UNREACHABLE(); |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | void LocationsBuilderARM64::VisitVecUShr(HVecUShr* instruction) { |
| 652 | CreateVecShiftLocations(GetGraph()->GetArena(), instruction); |
| 653 | } |
| 654 | |
| 655 | void InstructionCodeGeneratorARM64::VisitVecUShr(HVecUShr* instruction) { |
| 656 | LocationSummary* locations = instruction->GetLocations(); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 657 | VRegister lhs = VRegisterFrom(locations->InAt(0)); |
| 658 | VRegister dst = VRegisterFrom(locations->Out()); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 659 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 660 | switch (instruction->GetPackedType()) { |
| 661 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 662 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 663 | __ Ushr(dst.V16B(), lhs.V16B(), value); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 664 | break; |
| 665 | case Primitive::kPrimChar: |
| 666 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 667 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 668 | __ Ushr(dst.V8H(), lhs.V8H(), value); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 669 | break; |
| 670 | case Primitive::kPrimInt: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 671 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 672 | __ Ushr(dst.V4S(), lhs.V4S(), value); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 673 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 674 | case Primitive::kPrimLong: |
| 675 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 676 | __ Ushr(dst.V2D(), lhs.V2D(), value); |
| 677 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 678 | default: |
| 679 | LOG(FATAL) << "Unsupported SIMD type"; |
| 680 | UNREACHABLE(); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | // Helper to set up locations for vector memory operations. |
| 685 | static void CreateVecMemLocations(ArenaAllocator* arena, |
| 686 | HVecMemoryOperation* instruction, |
| 687 | bool is_load) { |
| 688 | LocationSummary* locations = new (arena) LocationSummary(instruction); |
| 689 | switch (instruction->GetPackedType()) { |
| 690 | case Primitive::kPrimBoolean: |
| 691 | case Primitive::kPrimByte: |
| 692 | case Primitive::kPrimChar: |
| 693 | case Primitive::kPrimShort: |
| 694 | case Primitive::kPrimInt: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 695 | case Primitive::kPrimLong: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 696 | case Primitive::kPrimFloat: |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 697 | case Primitive::kPrimDouble: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 698 | locations->SetInAt(0, Location::RequiresRegister()); |
| 699 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 700 | if (is_load) { |
| 701 | locations->SetOut(Location::RequiresFpuRegister()); |
| 702 | } else { |
| 703 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 704 | } |
| 705 | break; |
| 706 | default: |
| 707 | LOG(FATAL) << "Unsupported SIMD type"; |
| 708 | UNREACHABLE(); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | // Helper to set up registers and address for vector memory operations. |
| 713 | MemOperand InstructionCodeGeneratorARM64::CreateVecMemRegisters( |
| 714 | HVecMemoryOperation* instruction, |
| 715 | Location* reg_loc, |
| 716 | bool is_load) { |
| 717 | LocationSummary* locations = instruction->GetLocations(); |
| 718 | Register base = InputRegisterAt(instruction, 0); |
| 719 | Location index = locations->InAt(1); |
| 720 | *reg_loc = is_load ? locations->Out() : locations->InAt(2); |
| 721 | |
| 722 | Primitive::Type packed_type = instruction->GetPackedType(); |
| 723 | uint32_t offset = mirror::Array::DataOffset(Primitive::ComponentSize(packed_type)).Uint32Value(); |
| 724 | size_t shift = Primitive::ComponentSizeShift(packed_type); |
| 725 | |
| 726 | UseScratchRegisterScope temps(GetVIXLAssembler()); |
| 727 | Register temp = temps.AcquireSameSizeAs(base); |
| 728 | if (index.IsConstant()) { |
| 729 | offset += Int64ConstantFrom(index) << shift; |
| 730 | __ Add(temp, base, offset); |
| 731 | } else { |
| 732 | if (instruction->InputAt(0)->IsIntermediateAddress()) { |
| 733 | temp = base; |
| 734 | } else { |
| 735 | __ Add(temp, base, offset); |
| 736 | } |
| 737 | __ Add(temp.X(), temp.X(), Operand(XRegisterFrom(index), LSL, shift)); |
| 738 | } |
| 739 | return HeapOperand(temp); |
| 740 | } |
| 741 | |
| 742 | void LocationsBuilderARM64::VisitVecLoad(HVecLoad* instruction) { |
| 743 | CreateVecMemLocations(GetGraph()->GetArena(), instruction, /*is_load*/ true); |
| 744 | } |
| 745 | |
| 746 | void InstructionCodeGeneratorARM64::VisitVecLoad(HVecLoad* instruction) { |
| 747 | Location reg_loc = Location::NoLocation(); |
| 748 | MemOperand mem = CreateVecMemRegisters(instruction, ®_loc, /*is_load*/ true); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 749 | VRegister reg = VRegisterFrom(reg_loc); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 750 | switch (instruction->GetPackedType()) { |
| 751 | case Primitive::kPrimBoolean: |
| 752 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 753 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 754 | __ Ld1(reg.V16B(), mem); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 755 | break; |
| 756 | case Primitive::kPrimChar: |
| 757 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 758 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 759 | __ Ld1(reg.V8H(), mem); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 760 | break; |
| 761 | case Primitive::kPrimInt: |
| 762 | case Primitive::kPrimFloat: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 763 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 764 | __ Ld1(reg.V4S(), mem); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 765 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 766 | case Primitive::kPrimLong: |
| 767 | case Primitive::kPrimDouble: |
| 768 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 769 | __ Ld1(reg.V2D(), mem); |
| 770 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 771 | default: |
| 772 | LOG(FATAL) << "Unsupported SIMD type"; |
| 773 | UNREACHABLE(); |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | void LocationsBuilderARM64::VisitVecStore(HVecStore* instruction) { |
| 778 | CreateVecMemLocations(GetGraph()->GetArena(), instruction, /*is_load*/ false); |
| 779 | } |
| 780 | |
| 781 | void InstructionCodeGeneratorARM64::VisitVecStore(HVecStore* instruction) { |
| 782 | Location reg_loc = Location::NoLocation(); |
| 783 | MemOperand mem = CreateVecMemRegisters(instruction, ®_loc, /*is_load*/ false); |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 784 | VRegister reg = VRegisterFrom(reg_loc); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 785 | switch (instruction->GetPackedType()) { |
| 786 | case Primitive::kPrimBoolean: |
| 787 | case Primitive::kPrimByte: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 788 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 789 | __ St1(reg.V16B(), mem); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 790 | break; |
| 791 | case Primitive::kPrimChar: |
| 792 | case Primitive::kPrimShort: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 793 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 794 | __ St1(reg.V8H(), mem); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 795 | break; |
| 796 | case Primitive::kPrimInt: |
| 797 | case Primitive::kPrimFloat: |
| Artem Serov | d4bccf1 | 2017-04-03 18:47:32 +0100 | [diff] [blame] | 798 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 799 | __ St1(reg.V4S(), mem); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 800 | break; |
| Artem Serov | b31f91f | 2017-04-05 11:31:19 +0100 | [diff] [blame] | 801 | case Primitive::kPrimLong: |
| 802 | case Primitive::kPrimDouble: |
| 803 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 804 | __ St1(reg.V2D(), mem); |
| 805 | break; |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 806 | default: |
| 807 | LOG(FATAL) << "Unsupported SIMD type"; |
| 808 | UNREACHABLE(); |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | #undef __ |
| 813 | |
| 814 | } // namespace arm64 |
| 815 | } // namespace art |