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_x86.h" |
Andreas Gampe | 895f922 | 2017-07-05 09:53:32 -0700 | [diff] [blame] | 18 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 19 | #include "mirror/array-inl.h" |
Andreas Gampe | 895f922 | 2017-07-05 09:53:32 -0700 | [diff] [blame] | 20 | #include "mirror/string.h" |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 21 | |
| 22 | namespace art { |
| 23 | namespace x86 { |
| 24 | |
| 25 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 26 | #define __ down_cast<X86Assembler*>(GetAssembler())-> // NOLINT |
| 27 | |
| 28 | void LocationsBuilderX86::VisitVecReplicateScalar(HVecReplicateScalar* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 29 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 30 | HInstruction* input = instruction->InputAt(0); |
| 31 | bool is_zero = IsZeroBitPattern(input); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 32 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 33 | case DataType::Type::kInt64: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 34 | // Long needs extra temporary to load from the register pair. |
| 35 | if (!is_zero) { |
| 36 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 37 | } |
| 38 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 39 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 40 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 41 | case DataType::Type::kInt8: |
| 42 | case DataType::Type::kUint16: |
| 43 | case DataType::Type::kInt16: |
| 44 | case DataType::Type::kInt32: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 45 | locations->SetInAt(0, is_zero ? Location::ConstantLocation(input->AsConstant()) |
| 46 | : Location::RequiresRegister()); |
| 47 | locations->SetOut(Location::RequiresFpuRegister()); |
| 48 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 49 | case DataType::Type::kFloat32: |
| 50 | case DataType::Type::kFloat64: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 51 | locations->SetInAt(0, is_zero ? Location::ConstantLocation(input->AsConstant()) |
| 52 | : Location::RequiresFpuRegister()); |
| 53 | locations->SetOut(is_zero ? Location::RequiresFpuRegister() |
| 54 | : Location::SameAsFirstInput()); |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 55 | break; |
| 56 | default: |
| 57 | LOG(FATAL) << "Unsupported SIMD type"; |
| 58 | UNREACHABLE(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void InstructionCodeGeneratorX86::VisitVecReplicateScalar(HVecReplicateScalar* instruction) { |
| 63 | LocationSummary* locations = instruction->GetLocations(); |
| 64 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 65 | |
| 66 | // Shorthand for any type of zero. |
| 67 | if (IsZeroBitPattern(instruction->InputAt(0))) { |
| 68 | __ xorps(dst, dst); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 73 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 74 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 75 | case DataType::Type::kInt8: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 76 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 77 | __ movd(dst, locations->InAt(0).AsRegister<Register>()); |
| 78 | __ punpcklbw(dst, dst); |
| 79 | __ punpcklwd(dst, dst); |
| 80 | __ pshufd(dst, dst, Immediate(0)); |
| 81 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 82 | case DataType::Type::kUint16: |
| 83 | case DataType::Type::kInt16: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 84 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 85 | __ movd(dst, locations->InAt(0).AsRegister<Register>()); |
| 86 | __ punpcklwd(dst, dst); |
| 87 | __ pshufd(dst, dst, Immediate(0)); |
| 88 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 89 | case DataType::Type::kInt32: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 90 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 91 | __ movd(dst, locations->InAt(0).AsRegister<Register>()); |
| 92 | __ pshufd(dst, dst, Immediate(0)); |
| 93 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 94 | case DataType::Type::kInt64: { |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 95 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 96 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 97 | __ movd(dst, locations->InAt(0).AsRegisterPairLow<Register>()); |
| 98 | __ movd(tmp, locations->InAt(0).AsRegisterPairHigh<Register>()); |
| 99 | __ punpckldq(dst, tmp); |
| 100 | __ punpcklqdq(dst, dst); |
| 101 | break; |
| 102 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 103 | case DataType::Type::kFloat32: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 104 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 105 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 106 | __ shufps(dst, dst, Immediate(0)); |
| 107 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 108 | case DataType::Type::kFloat64: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 109 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 110 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 111 | __ shufpd(dst, dst, Immediate(0)); |
| 112 | break; |
| 113 | default: |
| 114 | LOG(FATAL) << "Unsupported SIMD type"; |
| 115 | UNREACHABLE(); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void LocationsBuilderX86::VisitVecExtractScalar(HVecExtractScalar* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 120 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 121 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 122 | case DataType::Type::kInt64: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 123 | // Long needs extra temporary to store into the register pair. |
Aart Bik | a57b4ee | 2017-08-30 21:21:41 +0000 | [diff] [blame] | 124 | locations->AddTemp(Location::RequiresFpuRegister()); |
Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 125 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 126 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 127 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 128 | case DataType::Type::kInt8: |
| 129 | case DataType::Type::kUint16: |
| 130 | case DataType::Type::kInt16: |
| 131 | case DataType::Type::kInt32: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 132 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 133 | locations->SetOut(Location::RequiresRegister()); |
Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 134 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 135 | case DataType::Type::kFloat32: |
| 136 | case DataType::Type::kFloat64: |
Aart Bik | a57b4ee | 2017-08-30 21:21:41 +0000 | [diff] [blame] | 137 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 138 | locations->SetOut(Location::SameAsFirstInput()); |
| 139 | break; |
| 140 | default: |
| 141 | LOG(FATAL) << "Unsupported SIMD type"; |
| 142 | UNREACHABLE(); |
| 143 | } |
| 144 | } |
| 145 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 146 | void InstructionCodeGeneratorX86::VisitVecExtractScalar(HVecExtractScalar* instruction) { |
Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 147 | LocationSummary* locations = instruction->GetLocations(); |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 148 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 149 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 150 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 151 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 152 | case DataType::Type::kInt8: |
| 153 | case DataType::Type::kUint16: |
| 154 | case DataType::Type::kInt16: // TODO: up to here, and? |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 155 | LOG(FATAL) << "Unsupported SIMD type"; |
| 156 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 157 | case DataType::Type::kInt32: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 158 | DCHECK_LE(4u, instruction->GetVectorLength()); |
| 159 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 160 | __ movd(locations->Out().AsRegister<Register>(), src); |
Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 161 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 162 | case DataType::Type::kInt64: { |
Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 163 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 164 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 165 | __ movd(locations->Out().AsRegisterPairLow<Register>(), src); |
| 166 | __ pshufd(tmp, src, Immediate(1)); |
| 167 | __ movd(locations->Out().AsRegisterPairHigh<Register>(), tmp); |
Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 168 | break; |
| 169 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 170 | case DataType::Type::kFloat32: |
| 171 | case DataType::Type::kFloat64: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 172 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 173 | DCHECK_LE(instruction->GetVectorLength(), 4u); |
| 174 | DCHECK(locations->InAt(0).Equals(locations->Out())); // no code required |
Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 175 | break; |
| 176 | default: |
| 177 | LOG(FATAL) << "Unsupported SIMD type"; |
| 178 | UNREACHABLE(); |
| 179 | } |
| 180 | } |
| 181 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 182 | // Helper to set up locations for vector unary operations. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 183 | static void CreateVecUnOpLocations(ArenaAllocator* allocator, HVecUnaryOperation* instruction) { |
| 184 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 185 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 186 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 187 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 188 | case DataType::Type::kInt8: |
| 189 | case DataType::Type::kUint16: |
| 190 | case DataType::Type::kInt16: |
| 191 | case DataType::Type::kInt32: |
| 192 | case DataType::Type::kInt64: |
| 193 | case DataType::Type::kFloat32: |
| 194 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 195 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 196 | locations->SetOut(Location::RequiresFpuRegister()); |
| 197 | break; |
| 198 | default: |
| 199 | LOG(FATAL) << "Unsupported SIMD type"; |
| 200 | UNREACHABLE(); |
| 201 | } |
| 202 | } |
| 203 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 204 | void LocationsBuilderX86::VisitVecReduce(HVecReduce* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 205 | CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 206 | // Long reduction or min/max require a temporary. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 207 | if (instruction->GetPackedType() == DataType::Type::kInt64 || |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 208 | instruction->GetKind() == HVecReduce::kMin || |
| 209 | instruction->GetKind() == HVecReduce::kMax) { |
| 210 | instruction->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void InstructionCodeGeneratorX86::VisitVecReduce(HVecReduce* instruction) { |
| 215 | LocationSummary* locations = instruction->GetLocations(); |
| 216 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 217 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 218 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 219 | case DataType::Type::kInt32: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 220 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 221 | switch (instruction->GetKind()) { |
| 222 | case HVecReduce::kSum: |
| 223 | __ movaps(dst, src); |
| 224 | __ phaddd(dst, dst); |
| 225 | __ phaddd(dst, dst); |
| 226 | break; |
| 227 | case HVecReduce::kMin: { |
| 228 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 229 | __ movaps(tmp, src); |
| 230 | __ movaps(dst, src); |
| 231 | __ psrldq(tmp, Immediate(8)); |
| 232 | __ pminsd(dst, tmp); |
| 233 | __ psrldq(tmp, Immediate(4)); |
| 234 | __ pminsd(dst, tmp); |
| 235 | break; |
| 236 | } |
| 237 | case HVecReduce::kMax: { |
| 238 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 239 | __ movaps(tmp, src); |
| 240 | __ movaps(dst, src); |
| 241 | __ psrldq(tmp, Immediate(8)); |
| 242 | __ pmaxsd(dst, tmp); |
| 243 | __ psrldq(tmp, Immediate(4)); |
| 244 | __ pmaxsd(dst, tmp); |
| 245 | break; |
| 246 | } |
| 247 | } |
| 248 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 249 | case DataType::Type::kInt64: { |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 250 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 251 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 252 | switch (instruction->GetKind()) { |
| 253 | case HVecReduce::kSum: |
| 254 | __ movaps(tmp, src); |
| 255 | __ movaps(dst, src); |
| 256 | __ punpckhqdq(tmp, tmp); |
| 257 | __ paddq(dst, tmp); |
| 258 | break; |
| 259 | case HVecReduce::kMin: |
| 260 | case HVecReduce::kMax: |
| 261 | LOG(FATAL) << "Unsupported SIMD type"; |
| 262 | } |
| 263 | break; |
| 264 | } |
| 265 | default: |
| 266 | LOG(FATAL) << "Unsupported SIMD type"; |
| 267 | UNREACHABLE(); |
| 268 | } |
| 269 | } |
| 270 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 271 | void LocationsBuilderX86::VisitVecCnv(HVecCnv* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 272 | CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | void InstructionCodeGeneratorX86::VisitVecCnv(HVecCnv* instruction) { |
| 276 | LocationSummary* locations = instruction->GetLocations(); |
| 277 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 278 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 279 | DataType::Type from = instruction->GetInputType(); |
| 280 | DataType::Type to = instruction->GetResultType(); |
| 281 | if (from == DataType::Type::kInt32 && to == DataType::Type::kFloat32) { |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 282 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 283 | __ cvtdq2ps(dst, src); |
| 284 | } else { |
| 285 | LOG(FATAL) << "Unsupported SIMD type"; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | void LocationsBuilderX86::VisitVecNeg(HVecNeg* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 290 | CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | void InstructionCodeGeneratorX86::VisitVecNeg(HVecNeg* instruction) { |
| 294 | LocationSummary* locations = instruction->GetLocations(); |
| 295 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 296 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 297 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 298 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 299 | case DataType::Type::kInt8: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 300 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 301 | __ pxor(dst, dst); |
| 302 | __ psubb(dst, src); |
| 303 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 304 | case DataType::Type::kUint16: |
| 305 | case DataType::Type::kInt16: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 306 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 307 | __ pxor(dst, dst); |
| 308 | __ psubw(dst, src); |
| 309 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 310 | case DataType::Type::kInt32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 311 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 312 | __ pxor(dst, dst); |
| 313 | __ psubd(dst, src); |
| 314 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 315 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 316 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 317 | __ pxor(dst, dst); |
| 318 | __ psubq(dst, src); |
| 319 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 320 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 321 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 322 | __ xorps(dst, dst); |
| 323 | __ subps(dst, src); |
| 324 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 325 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 326 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 327 | __ xorpd(dst, dst); |
| 328 | __ subpd(dst, src); |
| 329 | break; |
| 330 | default: |
| 331 | LOG(FATAL) << "Unsupported SIMD type"; |
| 332 | UNREACHABLE(); |
| 333 | } |
| 334 | } |
| 335 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 336 | void LocationsBuilderX86::VisitVecAbs(HVecAbs* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 337 | CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 338 | // Integral-abs requires a temporary for the comparison. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 339 | if (instruction->GetPackedType() == DataType::Type::kInt32) { |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 340 | instruction->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | void InstructionCodeGeneratorX86::VisitVecAbs(HVecAbs* instruction) { |
| 345 | LocationSummary* locations = instruction->GetLocations(); |
| 346 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 347 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 348 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 349 | case DataType::Type::kInt32: { |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 350 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 351 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 352 | __ movaps(dst, src); |
| 353 | __ pxor(tmp, tmp); |
| 354 | __ pcmpgtd(tmp, dst); |
| 355 | __ pxor(dst, tmp); |
| 356 | __ psubd(dst, tmp); |
| 357 | break; |
| 358 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 359 | case DataType::Type::kFloat32: |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 360 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 361 | __ pcmpeqb(dst, dst); // all ones |
| 362 | __ psrld(dst, Immediate(1)); |
| 363 | __ andps(dst, src); |
| 364 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 365 | case DataType::Type::kFloat64: |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 366 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 367 | __ pcmpeqb(dst, dst); // all ones |
| 368 | __ psrlq(dst, Immediate(1)); |
| 369 | __ andpd(dst, src); |
| 370 | break; |
| 371 | default: |
| 372 | LOG(FATAL) << "Unsupported SIMD type"; |
| 373 | UNREACHABLE(); |
| 374 | } |
| 375 | } |
| 376 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 377 | void LocationsBuilderX86::VisitVecNot(HVecNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 378 | CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 379 | // Boolean-not requires a temporary to construct the 16 x one. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 380 | if (instruction->GetPackedType() == DataType::Type::kBool) { |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 381 | instruction->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | void InstructionCodeGeneratorX86::VisitVecNot(HVecNot* instruction) { |
| 386 | LocationSummary* locations = instruction->GetLocations(); |
| 387 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 388 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 389 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 390 | case DataType::Type::kBool: { // special case boolean-not |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 391 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 392 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 393 | __ pxor(dst, dst); |
| 394 | __ pcmpeqb(tmp, tmp); // all ones |
| 395 | __ psubb(dst, tmp); // 16 x one |
| 396 | __ pxor(dst, src); |
| 397 | break; |
| 398 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 399 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 400 | case DataType::Type::kInt8: |
| 401 | case DataType::Type::kUint16: |
| 402 | case DataType::Type::kInt16: |
| 403 | case DataType::Type::kInt32: |
| 404 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 405 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 406 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 407 | __ pcmpeqb(dst, dst); // all ones |
| 408 | __ pxor(dst, src); |
| 409 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 410 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 411 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 412 | __ pcmpeqb(dst, dst); // all ones |
| 413 | __ xorps(dst, src); |
| 414 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 415 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 416 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 417 | __ pcmpeqb(dst, dst); // all ones |
| 418 | __ xorpd(dst, src); |
| 419 | break; |
| 420 | default: |
| 421 | LOG(FATAL) << "Unsupported SIMD type"; |
| 422 | UNREACHABLE(); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | // Helper to set up locations for vector binary operations. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 427 | static void CreateVecBinOpLocations(ArenaAllocator* allocator, HVecBinaryOperation* instruction) { |
| 428 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 429 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 430 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 431 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 432 | case DataType::Type::kInt8: |
| 433 | case DataType::Type::kUint16: |
| 434 | case DataType::Type::kInt16: |
| 435 | case DataType::Type::kInt32: |
| 436 | case DataType::Type::kInt64: |
| 437 | case DataType::Type::kFloat32: |
| 438 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 439 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 440 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 441 | locations->SetOut(Location::SameAsFirstInput()); |
| 442 | break; |
| 443 | default: |
| 444 | LOG(FATAL) << "Unsupported SIMD type"; |
| 445 | UNREACHABLE(); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | void LocationsBuilderX86::VisitVecAdd(HVecAdd* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 450 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | void InstructionCodeGeneratorX86::VisitVecAdd(HVecAdd* instruction) { |
| 454 | LocationSummary* locations = instruction->GetLocations(); |
| 455 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 456 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 457 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 458 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 459 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 460 | case DataType::Type::kInt8: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 461 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 462 | __ paddb(dst, src); |
| 463 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 464 | case DataType::Type::kUint16: |
| 465 | case DataType::Type::kInt16: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 466 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 467 | __ paddw(dst, src); |
| 468 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 469 | case DataType::Type::kInt32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 470 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 471 | __ paddd(dst, src); |
| 472 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 473 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 474 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 475 | __ paddq(dst, src); |
| 476 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 477 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 478 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 479 | __ addps(dst, src); |
| 480 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 481 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 482 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 483 | __ addpd(dst, src); |
| 484 | break; |
| 485 | default: |
| 486 | LOG(FATAL) << "Unsupported SIMD type"; |
| 487 | UNREACHABLE(); |
| 488 | } |
| 489 | } |
| 490 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 491 | void LocationsBuilderX86::VisitVecHalvingAdd(HVecHalvingAdd* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 492 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void InstructionCodeGeneratorX86::VisitVecHalvingAdd(HVecHalvingAdd* instruction) { |
| 496 | LocationSummary* locations = instruction->GetLocations(); |
| 497 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 498 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 499 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 500 | |
| 501 | DCHECK(instruction->IsRounded()); |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 502 | |
| 503 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 504 | case DataType::Type::kUint8: |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 505 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 506 | __ pavgb(dst, src); |
| 507 | return; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 508 | case DataType::Type::kUint16: |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 509 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 510 | __ pavgw(dst, src); |
| 511 | return; |
| 512 | default: |
| 513 | LOG(FATAL) << "Unsupported SIMD type"; |
| 514 | UNREACHABLE(); |
| 515 | } |
| 516 | } |
| 517 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 518 | void LocationsBuilderX86::VisitVecSub(HVecSub* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 519 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | void InstructionCodeGeneratorX86::VisitVecSub(HVecSub* instruction) { |
| 523 | LocationSummary* locations = instruction->GetLocations(); |
| 524 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 525 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 526 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 527 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 528 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 529 | case DataType::Type::kInt8: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 530 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 531 | __ psubb(dst, src); |
| 532 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 533 | case DataType::Type::kUint16: |
| 534 | case DataType::Type::kInt16: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 535 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 536 | __ psubw(dst, src); |
| 537 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 538 | case DataType::Type::kInt32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 539 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 540 | __ psubd(dst, src); |
| 541 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 542 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 543 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 544 | __ psubq(dst, src); |
| 545 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 546 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 547 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 548 | __ subps(dst, src); |
| 549 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 550 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 551 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 552 | __ subpd(dst, src); |
| 553 | break; |
| 554 | default: |
| 555 | LOG(FATAL) << "Unsupported SIMD type"; |
| 556 | UNREACHABLE(); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | void LocationsBuilderX86::VisitVecMul(HVecMul* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 561 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | void InstructionCodeGeneratorX86::VisitVecMul(HVecMul* instruction) { |
| 565 | LocationSummary* locations = instruction->GetLocations(); |
| 566 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 567 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 568 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 569 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 570 | case DataType::Type::kUint16: |
| 571 | case DataType::Type::kInt16: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 572 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 573 | __ pmullw(dst, src); |
| 574 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 575 | case DataType::Type::kInt32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 576 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 577 | __ pmulld(dst, src); |
| 578 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 579 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 580 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 581 | __ mulps(dst, src); |
| 582 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 583 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 584 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 585 | __ mulpd(dst, src); |
| 586 | break; |
| 587 | default: |
| 588 | LOG(FATAL) << "Unsupported SIMD type"; |
| 589 | UNREACHABLE(); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | void LocationsBuilderX86::VisitVecDiv(HVecDiv* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 594 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | void InstructionCodeGeneratorX86::VisitVecDiv(HVecDiv* instruction) { |
| 598 | LocationSummary* locations = instruction->GetLocations(); |
| 599 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 600 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 601 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 602 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 603 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 604 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 605 | __ divps(dst, src); |
| 606 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 607 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 608 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 609 | __ divpd(dst, src); |
| 610 | break; |
| 611 | default: |
| 612 | LOG(FATAL) << "Unsupported SIMD type"; |
| 613 | UNREACHABLE(); |
| 614 | } |
| 615 | } |
| 616 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 617 | void LocationsBuilderX86::VisitVecMin(HVecMin* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 618 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | void InstructionCodeGeneratorX86::VisitVecMin(HVecMin* instruction) { |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 622 | LocationSummary* locations = instruction->GetLocations(); |
| 623 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 624 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 625 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 626 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 627 | case DataType::Type::kUint8: |
| 628 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 629 | __ pminub(dst, src); |
| 630 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 631 | case DataType::Type::kInt8: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 632 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 633 | __ pminsb(dst, src); |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 634 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 635 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 636 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 637 | __ pminuw(dst, src); |
| 638 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 639 | case DataType::Type::kInt16: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 640 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 641 | __ pminsw(dst, src); |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 642 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 643 | case DataType::Type::kInt32: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 644 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 645 | if (instruction->IsUnsigned()) { |
| 646 | __ pminud(dst, src); |
| 647 | } else { |
| 648 | __ pminsd(dst, src); |
| 649 | } |
| 650 | break; |
| 651 | // Next cases are sloppy wrt 0.0 vs -0.0. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 652 | case DataType::Type::kFloat32: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 653 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 654 | DCHECK(!instruction->IsUnsigned()); |
| 655 | __ minps(dst, src); |
| 656 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 657 | case DataType::Type::kFloat64: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 658 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 659 | DCHECK(!instruction->IsUnsigned()); |
| 660 | __ minpd(dst, src); |
| 661 | break; |
| 662 | default: |
| 663 | LOG(FATAL) << "Unsupported SIMD type"; |
| 664 | UNREACHABLE(); |
| 665 | } |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | void LocationsBuilderX86::VisitVecMax(HVecMax* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 669 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | void InstructionCodeGeneratorX86::VisitVecMax(HVecMax* instruction) { |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 673 | LocationSummary* locations = instruction->GetLocations(); |
| 674 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 675 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 676 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 677 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 678 | case DataType::Type::kUint8: |
| 679 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 680 | __ pmaxub(dst, src); |
| 681 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 682 | case DataType::Type::kInt8: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 683 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 684 | __ pmaxsb(dst, src); |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 685 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 686 | case DataType::Type::kUint16: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 687 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 688 | __ pmaxuw(dst, src); |
| 689 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 690 | case DataType::Type::kInt16: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 691 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 692 | __ pmaxsw(dst, src); |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 693 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 694 | case DataType::Type::kInt32: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 695 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 696 | if (instruction->IsUnsigned()) { |
| 697 | __ pmaxud(dst, src); |
| 698 | } else { |
| 699 | __ pmaxsd(dst, src); |
| 700 | } |
| 701 | break; |
| 702 | // Next cases are sloppy wrt 0.0 vs -0.0. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 703 | case DataType::Type::kFloat32: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 704 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 705 | DCHECK(!instruction->IsUnsigned()); |
| 706 | __ maxps(dst, src); |
| 707 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 708 | case DataType::Type::kFloat64: |
Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 709 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 710 | DCHECK(!instruction->IsUnsigned()); |
| 711 | __ maxpd(dst, src); |
| 712 | break; |
| 713 | default: |
| 714 | LOG(FATAL) << "Unsupported SIMD type"; |
| 715 | UNREACHABLE(); |
| 716 | } |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 719 | void LocationsBuilderX86::VisitVecAnd(HVecAnd* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 720 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | void InstructionCodeGeneratorX86::VisitVecAnd(HVecAnd* instruction) { |
| 724 | LocationSummary* locations = instruction->GetLocations(); |
| 725 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 726 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 727 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 728 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 729 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 730 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 731 | case DataType::Type::kInt8: |
| 732 | case DataType::Type::kUint16: |
| 733 | case DataType::Type::kInt16: |
| 734 | case DataType::Type::kInt32: |
| 735 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 736 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 737 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 738 | __ pand(dst, src); |
| 739 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 740 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 741 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 742 | __ andps(dst, src); |
| 743 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 744 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 745 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 746 | __ andpd(dst, src); |
| 747 | break; |
| 748 | default: |
| 749 | LOG(FATAL) << "Unsupported SIMD type"; |
| 750 | UNREACHABLE(); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | void LocationsBuilderX86::VisitVecAndNot(HVecAndNot* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 755 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | void InstructionCodeGeneratorX86::VisitVecAndNot(HVecAndNot* instruction) { |
| 759 | LocationSummary* locations = instruction->GetLocations(); |
| 760 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 761 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 762 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 763 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 764 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 765 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 766 | case DataType::Type::kInt8: |
| 767 | case DataType::Type::kUint16: |
| 768 | case DataType::Type::kInt16: |
| 769 | case DataType::Type::kInt32: |
| 770 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 771 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 772 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 773 | __ pandn(dst, src); |
| 774 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 775 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 776 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 777 | __ andnps(dst, src); |
| 778 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 779 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 780 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 781 | __ andnpd(dst, src); |
| 782 | break; |
| 783 | default: |
| 784 | LOG(FATAL) << "Unsupported SIMD type"; |
| 785 | UNREACHABLE(); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | void LocationsBuilderX86::VisitVecOr(HVecOr* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 790 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | void InstructionCodeGeneratorX86::VisitVecOr(HVecOr* instruction) { |
| 794 | LocationSummary* locations = instruction->GetLocations(); |
| 795 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 796 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 797 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 798 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 799 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 800 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 801 | case DataType::Type::kInt8: |
| 802 | case DataType::Type::kUint16: |
| 803 | case DataType::Type::kInt16: |
| 804 | case DataType::Type::kInt32: |
| 805 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 806 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 807 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 808 | __ por(dst, src); |
| 809 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 810 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 811 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 812 | __ orps(dst, src); |
| 813 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 814 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 815 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 816 | __ orpd(dst, src); |
| 817 | break; |
| 818 | default: |
| 819 | LOG(FATAL) << "Unsupported SIMD type"; |
| 820 | UNREACHABLE(); |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | void LocationsBuilderX86::VisitVecXor(HVecXor* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 825 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | void InstructionCodeGeneratorX86::VisitVecXor(HVecXor* instruction) { |
| 829 | LocationSummary* locations = instruction->GetLocations(); |
| 830 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 831 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 832 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 833 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 834 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 835 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 836 | case DataType::Type::kInt8: |
| 837 | case DataType::Type::kUint16: |
| 838 | case DataType::Type::kInt16: |
| 839 | case DataType::Type::kInt32: |
| 840 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 841 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 842 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 843 | __ pxor(dst, src); |
| 844 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 845 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 846 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 847 | __ xorps(dst, src); |
| 848 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 849 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 850 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 851 | __ xorpd(dst, src); |
| 852 | break; |
| 853 | default: |
| 854 | LOG(FATAL) << "Unsupported SIMD type"; |
| 855 | UNREACHABLE(); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | // Helper to set up locations for vector shift operations. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 860 | static void CreateVecShiftLocations(ArenaAllocator* allocator, HVecBinaryOperation* instruction) { |
| 861 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 862 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 863 | case DataType::Type::kUint16: |
| 864 | case DataType::Type::kInt16: |
| 865 | case DataType::Type::kInt32: |
| 866 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 867 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 868 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 869 | locations->SetOut(Location::SameAsFirstInput()); |
| 870 | break; |
| 871 | default: |
| 872 | LOG(FATAL) << "Unsupported SIMD type"; |
| 873 | UNREACHABLE(); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | void LocationsBuilderX86::VisitVecShl(HVecShl* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 878 | CreateVecShiftLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | void InstructionCodeGeneratorX86::VisitVecShl(HVecShl* instruction) { |
| 882 | LocationSummary* locations = instruction->GetLocations(); |
| 883 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 884 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 885 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 886 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 887 | case DataType::Type::kUint16: |
| 888 | case DataType::Type::kInt16: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 889 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 890 | __ psllw(dst, Immediate(static_cast<uint8_t>(value))); |
| 891 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 892 | case DataType::Type::kInt32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 893 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 894 | __ pslld(dst, Immediate(static_cast<uint8_t>(value))); |
| 895 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 896 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 897 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 898 | __ psllq(dst, Immediate(static_cast<uint8_t>(value))); |
| 899 | break; |
| 900 | default: |
| 901 | LOG(FATAL) << "Unsupported SIMD type"; |
| 902 | UNREACHABLE(); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | void LocationsBuilderX86::VisitVecShr(HVecShr* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 907 | CreateVecShiftLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | void InstructionCodeGeneratorX86::VisitVecShr(HVecShr* instruction) { |
| 911 | LocationSummary* locations = instruction->GetLocations(); |
| 912 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 913 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 914 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 915 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 916 | case DataType::Type::kUint16: |
| 917 | case DataType::Type::kInt16: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 918 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 919 | __ psraw(dst, Immediate(static_cast<uint8_t>(value))); |
| 920 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 921 | case DataType::Type::kInt32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 922 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 923 | __ psrad(dst, Immediate(static_cast<uint8_t>(value))); |
| 924 | break; |
| 925 | default: |
| 926 | LOG(FATAL) << "Unsupported SIMD type"; |
| 927 | UNREACHABLE(); |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | void LocationsBuilderX86::VisitVecUShr(HVecUShr* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 932 | CreateVecShiftLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | void InstructionCodeGeneratorX86::VisitVecUShr(HVecUShr* instruction) { |
| 936 | LocationSummary* locations = instruction->GetLocations(); |
| 937 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 938 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 939 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 940 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 941 | case DataType::Type::kUint16: |
| 942 | case DataType::Type::kInt16: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 943 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 944 | __ psrlw(dst, Immediate(static_cast<uint8_t>(value))); |
| 945 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 946 | case DataType::Type::kInt32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 947 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 948 | __ psrld(dst, Immediate(static_cast<uint8_t>(value))); |
| 949 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 950 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 951 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 952 | __ psrlq(dst, Immediate(static_cast<uint8_t>(value))); |
| 953 | break; |
| 954 | default: |
| 955 | LOG(FATAL) << "Unsupported SIMD type"; |
| 956 | UNREACHABLE(); |
| 957 | } |
| 958 | } |
| 959 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 960 | void LocationsBuilderX86::VisitVecSetScalars(HVecSetScalars* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 961 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 962 | |
| 963 | DCHECK_EQ(1u, instruction->InputCount()); // only one input currently implemented |
| 964 | |
| 965 | HInstruction* input = instruction->InputAt(0); |
| 966 | bool is_zero = IsZeroBitPattern(input); |
| 967 | |
| 968 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 969 | case DataType::Type::kInt64: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 970 | // Long needs extra temporary to load from register pairs. |
| 971 | if (!is_zero) { |
| 972 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 973 | } |
| 974 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 975 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 976 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 977 | case DataType::Type::kInt8: |
| 978 | case DataType::Type::kUint16: |
| 979 | case DataType::Type::kInt16: |
| 980 | case DataType::Type::kInt32: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 981 | locations->SetInAt(0, is_zero ? Location::ConstantLocation(input->AsConstant()) |
| 982 | : Location::RequiresRegister()); |
| 983 | locations->SetOut(Location::RequiresFpuRegister()); |
| 984 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 985 | case DataType::Type::kFloat32: |
| 986 | case DataType::Type::kFloat64: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 987 | locations->SetInAt(0, is_zero ? Location::ConstantLocation(input->AsConstant()) |
| 988 | : Location::RequiresFpuRegister()); |
| 989 | locations->SetOut(Location::RequiresFpuRegister()); |
| 990 | break; |
| 991 | default: |
| 992 | LOG(FATAL) << "Unsupported SIMD type"; |
| 993 | UNREACHABLE(); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | void InstructionCodeGeneratorX86::VisitVecSetScalars(HVecSetScalars* instruction) { |
| 998 | LocationSummary* locations = instruction->GetLocations(); |
| 999 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 1000 | |
| 1001 | DCHECK_EQ(1u, instruction->InputCount()); // only one input currently implemented |
| 1002 | |
| 1003 | // Zero out all other elements first. |
| 1004 | __ xorps(dst, dst); |
| 1005 | |
| 1006 | // Shorthand for any type of zero. |
| 1007 | if (IsZeroBitPattern(instruction->InputAt(0))) { |
| 1008 | return; |
| 1009 | } |
| 1010 | |
| 1011 | // Set required elements. |
| 1012 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1013 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1014 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1015 | case DataType::Type::kInt8: |
| 1016 | case DataType::Type::kUint16: |
| 1017 | case DataType::Type::kInt16: // TODO: up to here, and? |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1018 | LOG(FATAL) << "Unsupported SIMD type"; |
| 1019 | UNREACHABLE(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1020 | case DataType::Type::kInt32: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1021 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1022 | __ movd(dst, locations->InAt(0).AsRegister<Register>()); |
| 1023 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1024 | case DataType::Type::kInt64: { |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1025 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1026 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1027 | __ xorps(tmp, tmp); |
| 1028 | __ movd(dst, locations->InAt(0).AsRegisterPairLow<Register>()); |
| 1029 | __ movd(tmp, locations->InAt(0).AsRegisterPairHigh<Register>()); |
| 1030 | __ punpckldq(dst, tmp); |
| 1031 | break; |
| 1032 | } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1033 | case DataType::Type::kFloat32: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1034 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1035 | __ movss(dst, locations->InAt(1).AsFpuRegister<XmmRegister>()); |
| 1036 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1037 | case DataType::Type::kFloat64: |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1038 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1039 | __ movsd(dst, locations->InAt(1).AsFpuRegister<XmmRegister>()); |
| 1040 | break; |
| 1041 | default: |
| 1042 | LOG(FATAL) << "Unsupported SIMD type"; |
| 1043 | UNREACHABLE(); |
| 1044 | } |
| 1045 | } |
| 1046 | |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1047 | // Helper to set up locations for vector accumulations. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1048 | static void CreateVecAccumLocations(ArenaAllocator* allocator, HVecOperation* instruction) { |
| 1049 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1050 | switch (instruction->GetPackedType()) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1051 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1052 | case DataType::Type::kInt8: |
| 1053 | case DataType::Type::kUint16: |
| 1054 | case DataType::Type::kInt16: |
| 1055 | case DataType::Type::kInt32: |
| 1056 | case DataType::Type::kInt64: |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1057 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1058 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1059 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 1060 | locations->SetOut(Location::SameAsFirstInput()); |
| 1061 | break; |
| 1062 | default: |
| 1063 | LOG(FATAL) << "Unsupported SIMD type"; |
| 1064 | UNREACHABLE(); |
| 1065 | } |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1066 | } |
| 1067 | |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1068 | void LocationsBuilderX86::VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1069 | CreateVecAccumLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | void InstructionCodeGeneratorX86::VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) { |
| 1073 | // TODO: pmaddwd? |
| 1074 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 1075 | } |
| 1076 | |
| 1077 | void LocationsBuilderX86::VisitVecSADAccumulate(HVecSADAccumulate* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1078 | CreateVecAccumLocations(GetGraph()->GetAllocator(), instruction); |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | void InstructionCodeGeneratorX86::VisitVecSADAccumulate(HVecSADAccumulate* instruction) { |
| 1082 | // TODO: psadbw for unsigned? |
| 1083 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1084 | } |
| 1085 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1086 | // Helper to set up locations for vector memory operations. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1087 | static void CreateVecMemLocations(ArenaAllocator* allocator, |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1088 | HVecMemoryOperation* instruction, |
| 1089 | bool is_load) { |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1090 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1091 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1092 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1093 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1094 | case DataType::Type::kInt8: |
| 1095 | case DataType::Type::kUint16: |
| 1096 | case DataType::Type::kInt16: |
| 1097 | case DataType::Type::kInt32: |
| 1098 | case DataType::Type::kInt64: |
| 1099 | case DataType::Type::kFloat32: |
| 1100 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1101 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1102 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1103 | if (is_load) { |
| 1104 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1105 | } else { |
| 1106 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 1107 | } |
| 1108 | break; |
| 1109 | default: |
| 1110 | LOG(FATAL) << "Unsupported SIMD type"; |
| 1111 | UNREACHABLE(); |
| 1112 | } |
| 1113 | } |
| 1114 | |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1115 | // Helper to construct address for vector memory operations. |
| 1116 | static Address VecAddress(LocationSummary* locations, size_t size, bool is_string_char_at) { |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1117 | Location base = locations->InAt(0); |
| 1118 | Location index = locations->InAt(1); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1119 | ScaleFactor scale = TIMES_1; |
| 1120 | switch (size) { |
| 1121 | case 2: scale = TIMES_2; break; |
| 1122 | case 4: scale = TIMES_4; break; |
| 1123 | case 8: scale = TIMES_8; break; |
| 1124 | default: break; |
| 1125 | } |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1126 | // Incorporate the string or array offset in the address computation. |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1127 | uint32_t offset = is_string_char_at |
| 1128 | ? mirror::String::ValueOffset().Uint32Value() |
| 1129 | : mirror::Array::DataOffset(size).Uint32Value(); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1130 | return CodeGeneratorX86::ArrayAddress(base.AsRegister<Register>(), index, scale, offset); |
| 1131 | } |
| 1132 | |
| 1133 | void LocationsBuilderX86::VisitVecLoad(HVecLoad* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1134 | CreateVecMemLocations(GetGraph()->GetAllocator(), instruction, /*is_load*/ true); |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1135 | // String load requires a temporary for the compressed load. |
| 1136 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 1137 | instruction->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 1138 | } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | void InstructionCodeGeneratorX86::VisitVecLoad(HVecLoad* instruction) { |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1142 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1143 | size_t size = DataType::Size(instruction->GetPackedType()); |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1144 | Address address = VecAddress(locations, size, instruction->IsStringCharAt()); |
| 1145 | XmmRegister reg = locations->Out().AsFpuRegister<XmmRegister>(); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1146 | bool is_aligned16 = instruction->GetAlignment().IsAlignedAt(16); |
| 1147 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1148 | case DataType::Type::kUint16: |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1149 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 1150 | // Special handling of compressed/uncompressed string load. |
| 1151 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 1152 | NearLabel done, not_compressed; |
| 1153 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1154 | // Test compression bit. |
| 1155 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1156 | "Expecting 0=compressed, 1=uncompressed"); |
| 1157 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 1158 | __ testb(Address(locations->InAt(0).AsRegister<Register>(), count_offset), Immediate(1)); |
| 1159 | __ j(kNotZero, ¬_compressed); |
| 1160 | // Zero extend 8 compressed bytes into 8 chars. |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1161 | __ movsd(reg, VecAddress(locations, 1, instruction->IsStringCharAt())); |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1162 | __ pxor(tmp, tmp); |
| 1163 | __ punpcklbw(reg, tmp); |
| 1164 | __ jmp(&done); |
| 1165 | // Load 4 direct uncompressed chars. |
| 1166 | __ Bind(¬_compressed); |
| 1167 | is_aligned16 ? __ movdqa(reg, address) : __ movdqu(reg, address); |
| 1168 | __ Bind(&done); |
| 1169 | return; |
| 1170 | } |
| 1171 | FALLTHROUGH_INTENDED; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1172 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1173 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1174 | case DataType::Type::kInt8: |
| 1175 | case DataType::Type::kInt16: |
| 1176 | case DataType::Type::kInt32: |
| 1177 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1178 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 1179 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 1180 | is_aligned16 ? __ movdqa(reg, address) : __ movdqu(reg, address); |
| 1181 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1182 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1183 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1184 | is_aligned16 ? __ movaps(reg, address) : __ movups(reg, address); |
| 1185 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1186 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1187 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1188 | is_aligned16 ? __ movapd(reg, address) : __ movupd(reg, address); |
| 1189 | break; |
| 1190 | default: |
| 1191 | LOG(FATAL) << "Unsupported SIMD type"; |
| 1192 | UNREACHABLE(); |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | void LocationsBuilderX86::VisitVecStore(HVecStore* instruction) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1197 | CreateVecMemLocations(GetGraph()->GetAllocator(), instruction, /*is_load*/ false); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
| 1200 | void InstructionCodeGeneratorX86::VisitVecStore(HVecStore* instruction) { |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1201 | LocationSummary* locations = instruction->GetLocations(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1202 | size_t size = DataType::Size(instruction->GetPackedType()); |
Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1203 | Address address = VecAddress(locations, size, /*is_string_char_at*/ false); |
| 1204 | XmmRegister reg = locations->InAt(2).AsFpuRegister<XmmRegister>(); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1205 | bool is_aligned16 = instruction->GetAlignment().IsAlignedAt(16); |
| 1206 | switch (instruction->GetPackedType()) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1207 | case DataType::Type::kBool: |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1208 | case DataType::Type::kUint8: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1209 | case DataType::Type::kInt8: |
| 1210 | case DataType::Type::kUint16: |
| 1211 | case DataType::Type::kInt16: |
| 1212 | case DataType::Type::kInt32: |
| 1213 | case DataType::Type::kInt64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1214 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 1215 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 1216 | is_aligned16 ? __ movdqa(address, reg) : __ movdqu(address, reg); |
| 1217 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1218 | case DataType::Type::kFloat32: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1219 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1220 | is_aligned16 ? __ movaps(address, reg) : __ movups(address, reg); |
| 1221 | break; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1222 | case DataType::Type::kFloat64: |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1223 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1224 | is_aligned16 ? __ movapd(address, reg) : __ movupd(address, reg); |
| 1225 | break; |
| 1226 | default: |
| 1227 | LOG(FATAL) << "Unsupported SIMD type"; |
| 1228 | UNREACHABLE(); |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | #undef __ |
| 1233 | |
| 1234 | } // namespace x86 |
| 1235 | } // namespace art |