| 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: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 57 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 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 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Aart Bik | b67f7e2 | 2018-01-18 13:29:19 -0800 | [diff] [blame] | 96 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 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_EQ(4u, instruction->GetVectorLength()); |
| Aart Bik | b67f7e2 | 2018-01-18 13:29:19 -0800 | [diff] [blame] | 105 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 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_EQ(2u, instruction->GetVectorLength()); |
| Aart Bik | b67f7e2 | 2018-01-18 13:29:19 -0800 | [diff] [blame] | 110 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 111 | __ shufpd(dst, dst, Immediate(0)); |
| 112 | break; |
| 113 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 114 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 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: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 141 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 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 | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 155 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 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 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Aart Bik | b67f7e2 | 2018-01-18 13:29:19 -0800 | [diff] [blame] | 164 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 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: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 177 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 9879d0e | 2017-08-15 10:51:25 -0700 | [diff] [blame] | 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: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 199 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 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 || |
| Vladimir Marko | 4e3734a | 2018-11-14 15:45:28 +0000 | [diff] [blame] | 208 | instruction->GetReductionKind() == HVecReduce::kMin || |
| 209 | instruction->GetReductionKind() == HVecReduce::kMax) { |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 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()); |
| Vladimir Marko | 4e3734a | 2018-11-14 15:45:28 +0000 | [diff] [blame] | 221 | switch (instruction->GetReductionKind()) { |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 222 | case HVecReduce::kSum: |
| 223 | __ movaps(dst, src); |
| 224 | __ phaddd(dst, dst); |
| 225 | __ phaddd(dst, dst); |
| 226 | break; |
| Vladimir Marko | 8786fd9 | 2018-11-14 15:47:03 +0000 | [diff] [blame] | 227 | case HVecReduce::kMin: |
| 228 | case HVecReduce::kMax: |
| 229 | // Historical note: We've had a broken implementation here. b/117863065 |
| 230 | // Do not draw on the old code if we ever want to bring MIN/MAX reduction back. |
| 231 | LOG(FATAL) << "Unsupported reduction type."; |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 232 | } |
| 233 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 234 | case DataType::Type::kInt64: { |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 235 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 236 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 4e3734a | 2018-11-14 15:45:28 +0000 | [diff] [blame] | 237 | switch (instruction->GetReductionKind()) { |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 238 | case HVecReduce::kSum: |
| 239 | __ movaps(tmp, src); |
| 240 | __ movaps(dst, src); |
| 241 | __ punpckhqdq(tmp, tmp); |
| 242 | __ paddq(dst, tmp); |
| 243 | break; |
| 244 | case HVecReduce::kMin: |
| 245 | case HVecReduce::kMax: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 246 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 247 | } |
| 248 | break; |
| 249 | } |
| 250 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 251 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 252 | UNREACHABLE(); |
| 253 | } |
| 254 | } |
| 255 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 256 | void LocationsBuilderX86::VisitVecCnv(HVecCnv* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 257 | CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void InstructionCodeGeneratorX86::VisitVecCnv(HVecCnv* instruction) { |
| 261 | LocationSummary* locations = instruction->GetLocations(); |
| 262 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 263 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 264 | DataType::Type from = instruction->GetInputType(); |
| 265 | DataType::Type to = instruction->GetResultType(); |
| 266 | if (from == DataType::Type::kInt32 && to == DataType::Type::kFloat32) { |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 267 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 268 | __ cvtdq2ps(dst, src); |
| 269 | } else { |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 270 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
| 274 | void LocationsBuilderX86::VisitVecNeg(HVecNeg* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 275 | CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void InstructionCodeGeneratorX86::VisitVecNeg(HVecNeg* instruction) { |
| 279 | LocationSummary* locations = instruction->GetLocations(); |
| 280 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 281 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 282 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 283 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 284 | case DataType::Type::kInt8: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 285 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 286 | __ pxor(dst, dst); |
| 287 | __ psubb(dst, src); |
| 288 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 289 | case DataType::Type::kUint16: |
| 290 | case DataType::Type::kInt16: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 291 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 292 | __ pxor(dst, dst); |
| 293 | __ psubw(dst, src); |
| 294 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 295 | case DataType::Type::kInt32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 296 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 297 | __ pxor(dst, dst); |
| 298 | __ psubd(dst, src); |
| 299 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 300 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 301 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 302 | __ pxor(dst, dst); |
| 303 | __ psubq(dst, src); |
| 304 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 305 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 306 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 307 | __ xorps(dst, dst); |
| 308 | __ subps(dst, src); |
| 309 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 310 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 311 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 312 | __ xorpd(dst, dst); |
| 313 | __ subpd(dst, src); |
| 314 | break; |
| 315 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 316 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 317 | UNREACHABLE(); |
| 318 | } |
| 319 | } |
| 320 | |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 321 | void LocationsBuilderX86::VisitVecAbs(HVecAbs* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 322 | CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 323 | // Integral-abs requires a temporary for the comparison. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 324 | if (instruction->GetPackedType() == DataType::Type::kInt32) { |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 325 | instruction->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | void InstructionCodeGeneratorX86::VisitVecAbs(HVecAbs* instruction) { |
| 330 | LocationSummary* locations = instruction->GetLocations(); |
| 331 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 332 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 333 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 334 | case DataType::Type::kInt32: { |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 335 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 336 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 337 | __ movaps(dst, src); |
| 338 | __ pxor(tmp, tmp); |
| 339 | __ pcmpgtd(tmp, dst); |
| 340 | __ pxor(dst, tmp); |
| 341 | __ psubd(dst, tmp); |
| 342 | break; |
| 343 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 344 | case DataType::Type::kFloat32: |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 345 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 346 | __ pcmpeqb(dst, dst); // all ones |
| 347 | __ psrld(dst, Immediate(1)); |
| 348 | __ andps(dst, src); |
| 349 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 350 | case DataType::Type::kFloat64: |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 351 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 352 | __ pcmpeqb(dst, dst); // all ones |
| 353 | __ psrlq(dst, Immediate(1)); |
| 354 | __ andpd(dst, src); |
| 355 | break; |
| 356 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 357 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 358 | UNREACHABLE(); |
| 359 | } |
| 360 | } |
| 361 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 362 | void LocationsBuilderX86::VisitVecNot(HVecNot* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 363 | CreateVecUnOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 364 | // Boolean-not requires a temporary to construct the 16 x one. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 365 | if (instruction->GetPackedType() == DataType::Type::kBool) { |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 366 | instruction->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | void InstructionCodeGeneratorX86::VisitVecNot(HVecNot* instruction) { |
| 371 | LocationSummary* locations = instruction->GetLocations(); |
| 372 | XmmRegister src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| 373 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 374 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 375 | case DataType::Type::kBool: { // special case boolean-not |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 376 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 377 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 378 | __ pxor(dst, dst); |
| 379 | __ pcmpeqb(tmp, tmp); // all ones |
| 380 | __ psubb(dst, tmp); // 16 x one |
| 381 | __ pxor(dst, src); |
| 382 | break; |
| 383 | } |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 384 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 385 | case DataType::Type::kInt8: |
| 386 | case DataType::Type::kUint16: |
| 387 | case DataType::Type::kInt16: |
| 388 | case DataType::Type::kInt32: |
| 389 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 390 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 391 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 392 | __ pcmpeqb(dst, dst); // all ones |
| 393 | __ pxor(dst, src); |
| 394 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 395 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 396 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 397 | __ pcmpeqb(dst, dst); // all ones |
| 398 | __ xorps(dst, src); |
| 399 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 400 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 401 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 402 | __ pcmpeqb(dst, dst); // all ones |
| 403 | __ xorpd(dst, src); |
| 404 | break; |
| 405 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 406 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 407 | UNREACHABLE(); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | // Helper to set up locations for vector binary operations. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 412 | static void CreateVecBinOpLocations(ArenaAllocator* allocator, HVecBinaryOperation* instruction) { |
| 413 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 414 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 415 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 416 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 417 | case DataType::Type::kInt8: |
| 418 | case DataType::Type::kUint16: |
| 419 | case DataType::Type::kInt16: |
| 420 | case DataType::Type::kInt32: |
| 421 | case DataType::Type::kInt64: |
| 422 | case DataType::Type::kFloat32: |
| 423 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 424 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 425 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 426 | locations->SetOut(Location::SameAsFirstInput()); |
| 427 | break; |
| 428 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 429 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 430 | UNREACHABLE(); |
| 431 | } |
| 432 | } |
| 433 | |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 434 | static void CreateVecTerOpLocations(ArenaAllocator* allocator, HVecOperation* instruction) { |
| 435 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
| 436 | switch (instruction->GetPackedType()) { |
| 437 | case DataType::Type::kBool: |
| 438 | case DataType::Type::kUint8: |
| 439 | case DataType::Type::kInt8: |
| 440 | case DataType::Type::kUint16: |
| 441 | case DataType::Type::kInt16: |
| 442 | case DataType::Type::kInt32: |
| 443 | case DataType::Type::kInt64: |
| 444 | case DataType::Type::kFloat32: |
| 445 | case DataType::Type::kFloat64: |
| 446 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 447 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 448 | locations->SetOut(Location::RequiresFpuRegister()); |
| 449 | break; |
| 450 | default: |
| 451 | LOG(FATAL) << "Unsupported SIMD type"; |
| 452 | UNREACHABLE(); |
| 453 | } |
| 454 | } |
| 455 | |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 456 | void LocationsBuilderX86::VisitVecAdd(HVecAdd* instruction) { |
| 457 | if (CpuHasAvxFeatureFlag()) { |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 458 | CreateVecTerOpLocations(GetGraph()->GetAllocator(), instruction); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 459 | } else { |
| 460 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| 461 | } |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 462 | } |
| 463 | |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 464 | void InstructionCodeGeneratorX86::VisitVecAdd(HVecAdd* instruction) { |
| 465 | bool cpu_has_avx = CpuHasAvxFeatureFlag(); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 466 | LocationSummary* locations = instruction->GetLocations(); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 467 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 468 | XmmRegister other_src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 469 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 470 | DCHECK(cpu_has_avx || other_src == dst); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 471 | switch (instruction->GetPackedType()) { |
| 472 | case DataType::Type::kUint8: |
| 473 | case DataType::Type::kInt8: |
| 474 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 475 | cpu_has_avx ? __ vpaddb(dst, other_src, src) : __ paddb(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 476 | break; |
| 477 | case DataType::Type::kUint16: |
| 478 | case DataType::Type::kInt16: |
| 479 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 480 | cpu_has_avx ? __ vpaddw(dst, other_src, src) : __ paddw(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 481 | break; |
| 482 | case DataType::Type::kInt32: |
| 483 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 484 | cpu_has_avx ? __ vpaddd(dst, other_src, src) : __ paddd(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 485 | break; |
| 486 | case DataType::Type::kInt64: |
| 487 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 488 | cpu_has_avx ? __ vpaddq(dst, other_src, src) : __ paddq(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 489 | break; |
| 490 | case DataType::Type::kFloat32: |
| 491 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 492 | cpu_has_avx ? __ vaddps(dst, other_src, src) : __ addps(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 493 | break; |
| 494 | case DataType::Type::kFloat64: |
| 495 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 496 | cpu_has_avx ? __ vaddpd(dst, other_src, src) : __ addpd(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 497 | break; |
| 498 | default: |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 499 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 500 | UNREACHABLE(); |
| 501 | } |
| 502 | } |
| 503 | |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 504 | void LocationsBuilderX86::VisitVecSaturationAdd(HVecSaturationAdd* instruction) { |
| 505 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| 506 | } |
| 507 | |
| 508 | void InstructionCodeGeneratorX86::VisitVecSaturationAdd(HVecSaturationAdd* instruction) { |
| 509 | LocationSummary* locations = instruction->GetLocations(); |
| 510 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 511 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 512 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 513 | switch (instruction->GetPackedType()) { |
| 514 | case DataType::Type::kUint8: |
| 515 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 516 | __ paddusb(dst, src); |
| 517 | break; |
| 518 | case DataType::Type::kInt8: |
| 519 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 520 | __ paddsb(dst, src); |
| 521 | break; |
| 522 | case DataType::Type::kUint16: |
| 523 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 524 | __ paddusw(dst, src); |
| 525 | break; |
| 526 | case DataType::Type::kInt16: |
| 527 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 528 | __ paddsw(dst, src); |
| 529 | break; |
| 530 | default: |
| 531 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 532 | UNREACHABLE(); |
| 533 | } |
| 534 | } |
| 535 | |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 536 | void LocationsBuilderX86::VisitVecHalvingAdd(HVecHalvingAdd* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 537 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | void InstructionCodeGeneratorX86::VisitVecHalvingAdd(HVecHalvingAdd* instruction) { |
| 541 | LocationSummary* locations = instruction->GetLocations(); |
| 542 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 543 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 544 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 545 | |
| 546 | DCHECK(instruction->IsRounded()); |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 547 | |
| 548 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 549 | case DataType::Type::kUint8: |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 550 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 551 | __ pavgb(dst, src); |
| 552 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 553 | case DataType::Type::kUint16: |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 554 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 555 | __ pavgw(dst, src); |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 556 | break; |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 557 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 558 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 559 | UNREACHABLE(); |
| 560 | } |
| 561 | } |
| 562 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 563 | void LocationsBuilderX86::VisitVecSub(HVecSub* instruction) { |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 564 | if (CpuHasAvxFeatureFlag()) { |
| 565 | CreateVecTerOpLocations(GetGraph()->GetAllocator(), instruction); |
| 566 | } else { |
| 567 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 571 | void InstructionCodeGeneratorX86::VisitVecSub(HVecSub* instruction) { |
| 572 | bool cpu_has_avx = CpuHasAvxFeatureFlag(); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 573 | LocationSummary* locations = instruction->GetLocations(); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 574 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 575 | XmmRegister other_src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 576 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 577 | DCHECK(cpu_has_avx || other_src == dst); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 578 | switch (instruction->GetPackedType()) { |
| 579 | case DataType::Type::kUint8: |
| 580 | case DataType::Type::kInt8: |
| 581 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 582 | cpu_has_avx ? __ vpsubb(dst, other_src, src) : __ psubb(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 583 | break; |
| 584 | case DataType::Type::kUint16: |
| 585 | case DataType::Type::kInt16: |
| 586 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 587 | cpu_has_avx ? __ vpsubw(dst, other_src, src) : __ psubw(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 588 | break; |
| 589 | case DataType::Type::kInt32: |
| 590 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 591 | cpu_has_avx ? __ vpsubd(dst, other_src, src) : __ psubd(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 592 | break; |
| 593 | case DataType::Type::kInt64: |
| 594 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 595 | cpu_has_avx ? __ vpsubq(dst, other_src, src) : __ psubq(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 596 | break; |
| 597 | case DataType::Type::kFloat32: |
| 598 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 599 | cpu_has_avx ? __ vsubps(dst, other_src, src) : __ subps(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 600 | break; |
| 601 | case DataType::Type::kFloat64: |
| 602 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 603 | cpu_has_avx ? __ vsubpd(dst, other_src, src) : __ subpd(dst, src); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 604 | break; |
| 605 | default: |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 606 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Shalini Salomi Bodapati | 81d15be | 2019-05-30 11:00:42 +0530 | [diff] [blame] | 607 | UNREACHABLE(); |
| 608 | } |
| 609 | } |
| 610 | |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 611 | void LocationsBuilderX86::VisitVecSaturationSub(HVecSaturationSub* instruction) { |
| 612 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| 613 | } |
| 614 | |
| 615 | void InstructionCodeGeneratorX86::VisitVecSaturationSub(HVecSaturationSub* instruction) { |
| 616 | LocationSummary* locations = instruction->GetLocations(); |
| 617 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 618 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 619 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 620 | switch (instruction->GetPackedType()) { |
| 621 | case DataType::Type::kUint8: |
| 622 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 623 | __ psubusb(dst, src); |
| 624 | break; |
| 625 | case DataType::Type::kInt8: |
| 626 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 627 | __ psubsb(dst, src); |
| 628 | break; |
| 629 | case DataType::Type::kUint16: |
| 630 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 631 | __ psubusw(dst, src); |
| 632 | break; |
| 633 | case DataType::Type::kInt16: |
| 634 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 635 | __ psubsw(dst, src); |
| 636 | break; |
| 637 | default: |
| 638 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 639 | UNREACHABLE(); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | void LocationsBuilderX86::VisitVecMul(HVecMul* instruction) { |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 644 | if (CpuHasAvxFeatureFlag()) { |
| 645 | CreateVecTerOpLocations(GetGraph()->GetAllocator(), instruction); |
| 646 | } else { |
| 647 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| 648 | } |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | void InstructionCodeGeneratorX86::VisitVecMul(HVecMul* instruction) { |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 652 | bool cpu_has_avx = CpuHasAvxFeatureFlag(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 653 | LocationSummary* locations = instruction->GetLocations(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 654 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 655 | XmmRegister other_src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 656 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 657 | DCHECK(cpu_has_avx || other_src == dst); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 658 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 659 | case DataType::Type::kUint16: |
| 660 | case DataType::Type::kInt16: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 661 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 662 | cpu_has_avx ? __ vpmullw(dst, other_src, src) : __ pmullw(dst, src); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 663 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 664 | case DataType::Type::kInt32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 665 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 666 | cpu_has_avx ? __ vpmulld(dst, other_src, src) : __ pmulld(dst, src); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 667 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 668 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 669 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 670 | cpu_has_avx ? __ vmulps(dst, other_src, src) : __ mulps(dst, src); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 671 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 672 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 673 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 674 | cpu_has_avx ? __ vmulpd(dst, other_src, src) : __ mulpd(dst, src); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 675 | break; |
| 676 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 677 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 678 | UNREACHABLE(); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | void LocationsBuilderX86::VisitVecDiv(HVecDiv* instruction) { |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 683 | if (CpuHasAvxFeatureFlag()) { |
| 684 | CreateVecTerOpLocations(GetGraph()->GetAllocator(), instruction); |
| 685 | } else { |
| 686 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| 687 | } |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | void InstructionCodeGeneratorX86::VisitVecDiv(HVecDiv* instruction) { |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 691 | bool cpu_has_avx = CpuHasAvxFeatureFlag(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 692 | LocationSummary* locations = instruction->GetLocations(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 693 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 694 | XmmRegister other_src = locations->InAt(0).AsFpuRegister<XmmRegister>(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 695 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 696 | DCHECK(cpu_has_avx || other_src == dst); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 697 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 698 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 699 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 700 | cpu_has_avx ? __ vdivps(dst, other_src, src) : __ divps(dst, src); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 701 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 702 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 703 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Shalini Salomi Bodapati | b45a435 | 2019-07-10 16:09:41 +0530 | [diff] [blame] | 704 | cpu_has_avx ? __ vdivpd(dst, other_src, src) : __ divpd(dst, src); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 705 | break; |
| 706 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 707 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 708 | UNREACHABLE(); |
| 709 | } |
| 710 | } |
| 711 | |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 712 | void LocationsBuilderX86::VisitVecMin(HVecMin* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 713 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | void InstructionCodeGeneratorX86::VisitVecMin(HVecMin* instruction) { |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 717 | LocationSummary* locations = instruction->GetLocations(); |
| 718 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 719 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 720 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 721 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 722 | case DataType::Type::kUint8: |
| 723 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 724 | __ pminub(dst, src); |
| 725 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 726 | case DataType::Type::kInt8: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 727 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 728 | __ pminsb(dst, src); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 729 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 730 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 731 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 732 | __ pminuw(dst, src); |
| 733 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 734 | case DataType::Type::kInt16: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 735 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 736 | __ pminsw(dst, src); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 737 | break; |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 738 | case DataType::Type::kUint32: |
| 739 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 740 | __ pminud(dst, src); |
| 741 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 742 | case DataType::Type::kInt32: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 743 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 744 | __ pminsd(dst, src); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 745 | break; |
| 746 | // Next cases are sloppy wrt 0.0 vs -0.0. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 747 | case DataType::Type::kFloat32: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 748 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 749 | __ minps(dst, src); |
| 750 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 751 | case DataType::Type::kFloat64: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 752 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 753 | __ minpd(dst, src); |
| 754 | break; |
| 755 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 756 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 757 | UNREACHABLE(); |
| 758 | } |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | void LocationsBuilderX86::VisitVecMax(HVecMax* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 762 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | void InstructionCodeGeneratorX86::VisitVecMax(HVecMax* instruction) { |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 766 | LocationSummary* locations = instruction->GetLocations(); |
| 767 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 768 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 769 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 770 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 771 | case DataType::Type::kUint8: |
| 772 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| 773 | __ pmaxub(dst, src); |
| 774 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 775 | case DataType::Type::kInt8: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 776 | DCHECK_EQ(16u, instruction->GetVectorLength()); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 777 | __ pmaxsb(dst, src); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 778 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 779 | case DataType::Type::kUint16: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 780 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 781 | __ pmaxuw(dst, src); |
| 782 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 783 | case DataType::Type::kInt16: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 784 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 785 | __ pmaxsw(dst, src); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 786 | break; |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 787 | case DataType::Type::kUint32: |
| 788 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 789 | __ pmaxud(dst, src); |
| 790 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 791 | case DataType::Type::kInt32: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 792 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Aart Bik | 66c158e | 2018-01-31 12:55:04 -0800 | [diff] [blame] | 793 | __ pmaxsd(dst, src); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 794 | break; |
| 795 | // Next cases are sloppy wrt 0.0 vs -0.0. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 796 | case DataType::Type::kFloat32: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 797 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 798 | __ maxps(dst, src); |
| 799 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 800 | case DataType::Type::kFloat64: |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 801 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 802 | __ maxpd(dst, src); |
| 803 | break; |
| 804 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 805 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | c8e93c7 | 2017-05-10 10:49:22 -0700 | [diff] [blame] | 806 | UNREACHABLE(); |
| 807 | } |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 810 | void LocationsBuilderX86::VisitVecAnd(HVecAnd* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 811 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | void InstructionCodeGeneratorX86::VisitVecAnd(HVecAnd* instruction) { |
| 815 | LocationSummary* locations = instruction->GetLocations(); |
| 816 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 817 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 818 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 819 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 820 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 821 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 822 | case DataType::Type::kInt8: |
| 823 | case DataType::Type::kUint16: |
| 824 | case DataType::Type::kInt16: |
| 825 | case DataType::Type::kInt32: |
| 826 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 827 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 828 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 829 | __ pand(dst, src); |
| 830 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 831 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 832 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 833 | __ andps(dst, src); |
| 834 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 835 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 836 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 837 | __ andpd(dst, src); |
| 838 | break; |
| 839 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 840 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 841 | UNREACHABLE(); |
| 842 | } |
| 843 | } |
| 844 | |
| 845 | void LocationsBuilderX86::VisitVecAndNot(HVecAndNot* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 846 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | void InstructionCodeGeneratorX86::VisitVecAndNot(HVecAndNot* instruction) { |
| 850 | LocationSummary* locations = instruction->GetLocations(); |
| 851 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 852 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 853 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 854 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 855 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 856 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 857 | case DataType::Type::kInt8: |
| 858 | case DataType::Type::kUint16: |
| 859 | case DataType::Type::kInt16: |
| 860 | case DataType::Type::kInt32: |
| 861 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 862 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 863 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 864 | __ pandn(dst, src); |
| 865 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 866 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 867 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 868 | __ andnps(dst, src); |
| 869 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 870 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 871 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 872 | __ andnpd(dst, src); |
| 873 | break; |
| 874 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 875 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 876 | UNREACHABLE(); |
| 877 | } |
| 878 | } |
| 879 | |
| 880 | void LocationsBuilderX86::VisitVecOr(HVecOr* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 881 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | void InstructionCodeGeneratorX86::VisitVecOr(HVecOr* instruction) { |
| 885 | LocationSummary* locations = instruction->GetLocations(); |
| 886 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 887 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 888 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 889 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 890 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 891 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 892 | case DataType::Type::kInt8: |
| 893 | case DataType::Type::kUint16: |
| 894 | case DataType::Type::kInt16: |
| 895 | case DataType::Type::kInt32: |
| 896 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 897 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 898 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 899 | __ por(dst, src); |
| 900 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 901 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 902 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 903 | __ orps(dst, src); |
| 904 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 905 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 906 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 907 | __ orpd(dst, src); |
| 908 | break; |
| 909 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 910 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 911 | UNREACHABLE(); |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | void LocationsBuilderX86::VisitVecXor(HVecXor* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 916 | CreateVecBinOpLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | void InstructionCodeGeneratorX86::VisitVecXor(HVecXor* instruction) { |
| 920 | LocationSummary* locations = instruction->GetLocations(); |
| 921 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 922 | XmmRegister src = locations->InAt(1).AsFpuRegister<XmmRegister>(); |
| 923 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 924 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 925 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 926 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 927 | case DataType::Type::kInt8: |
| 928 | case DataType::Type::kUint16: |
| 929 | case DataType::Type::kInt16: |
| 930 | case DataType::Type::kInt32: |
| 931 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 932 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 933 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 934 | __ pxor(dst, src); |
| 935 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 936 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 937 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 938 | __ xorps(dst, src); |
| 939 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 940 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 941 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 942 | __ xorpd(dst, src); |
| 943 | break; |
| 944 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 945 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 946 | UNREACHABLE(); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | // Helper to set up locations for vector shift operations. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 951 | static void CreateVecShiftLocations(ArenaAllocator* allocator, HVecBinaryOperation* instruction) { |
| 952 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 953 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 954 | case DataType::Type::kUint16: |
| 955 | case DataType::Type::kInt16: |
| 956 | case DataType::Type::kInt32: |
| 957 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 958 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 959 | locations->SetInAt(1, Location::ConstantLocation(instruction->InputAt(1)->AsConstant())); |
| 960 | locations->SetOut(Location::SameAsFirstInput()); |
| 961 | break; |
| 962 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 963 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 964 | UNREACHABLE(); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | void LocationsBuilderX86::VisitVecShl(HVecShl* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 969 | CreateVecShiftLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | void InstructionCodeGeneratorX86::VisitVecShl(HVecShl* instruction) { |
| 973 | LocationSummary* locations = instruction->GetLocations(); |
| 974 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 975 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 976 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 977 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 978 | case DataType::Type::kUint16: |
| 979 | case DataType::Type::kInt16: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 980 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 981 | __ psllw(dst, Immediate(static_cast<uint8_t>(value))); |
| 982 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 983 | case DataType::Type::kInt32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 984 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 985 | __ pslld(dst, Immediate(static_cast<uint8_t>(value))); |
| 986 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 987 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 988 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 989 | __ psllq(dst, Immediate(static_cast<uint8_t>(value))); |
| 990 | break; |
| 991 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 992 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 993 | UNREACHABLE(); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | void LocationsBuilderX86::VisitVecShr(HVecShr* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 998 | CreateVecShiftLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | void InstructionCodeGeneratorX86::VisitVecShr(HVecShr* instruction) { |
| 1002 | LocationSummary* locations = instruction->GetLocations(); |
| 1003 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1004 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 1005 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 1006 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1007 | case DataType::Type::kUint16: |
| 1008 | case DataType::Type::kInt16: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1009 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 1010 | __ psraw(dst, Immediate(static_cast<uint8_t>(value))); |
| 1011 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1012 | case DataType::Type::kInt32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1013 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1014 | __ psrad(dst, Immediate(static_cast<uint8_t>(value))); |
| 1015 | break; |
| 1016 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1017 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1018 | UNREACHABLE(); |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | void LocationsBuilderX86::VisitVecUShr(HVecUShr* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1023 | CreateVecShiftLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | void InstructionCodeGeneratorX86::VisitVecUShr(HVecUShr* instruction) { |
| 1027 | LocationSummary* locations = instruction->GetLocations(); |
| 1028 | DCHECK(locations->InAt(0).Equals(locations->Out())); |
| 1029 | int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue(); |
| 1030 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 1031 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1032 | case DataType::Type::kUint16: |
| 1033 | case DataType::Type::kInt16: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1034 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 1035 | __ psrlw(dst, Immediate(static_cast<uint8_t>(value))); |
| 1036 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1037 | case DataType::Type::kInt32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1038 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1039 | __ psrld(dst, Immediate(static_cast<uint8_t>(value))); |
| 1040 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1041 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1042 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1043 | __ psrlq(dst, Immediate(static_cast<uint8_t>(value))); |
| 1044 | break; |
| 1045 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1046 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1047 | UNREACHABLE(); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1051 | void LocationsBuilderX86::VisitVecSetScalars(HVecSetScalars* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1052 | LocationSummary* locations = new (GetGraph()->GetAllocator()) LocationSummary(instruction); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1053 | |
| 1054 | DCHECK_EQ(1u, instruction->InputCount()); // only one input currently implemented |
| 1055 | |
| 1056 | HInstruction* input = instruction->InputAt(0); |
| 1057 | bool is_zero = IsZeroBitPattern(input); |
| 1058 | |
| 1059 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1060 | case DataType::Type::kInt64: |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1061 | // Long needs extra temporary to load from register pairs. |
| 1062 | if (!is_zero) { |
| 1063 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 1064 | } |
| 1065 | FALLTHROUGH_INTENDED; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1066 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1067 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1068 | case DataType::Type::kInt8: |
| 1069 | case DataType::Type::kUint16: |
| 1070 | case DataType::Type::kInt16: |
| 1071 | case DataType::Type::kInt32: |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1072 | locations->SetInAt(0, is_zero ? Location::ConstantLocation(input->AsConstant()) |
| 1073 | : Location::RequiresRegister()); |
| 1074 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1075 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1076 | case DataType::Type::kFloat32: |
| 1077 | case DataType::Type::kFloat64: |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1078 | locations->SetInAt(0, is_zero ? Location::ConstantLocation(input->AsConstant()) |
| 1079 | : Location::RequiresFpuRegister()); |
| 1080 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1081 | break; |
| 1082 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1083 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1084 | UNREACHABLE(); |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | void InstructionCodeGeneratorX86::VisitVecSetScalars(HVecSetScalars* instruction) { |
| 1089 | LocationSummary* locations = instruction->GetLocations(); |
| 1090 | XmmRegister dst = locations->Out().AsFpuRegister<XmmRegister>(); |
| 1091 | |
| 1092 | DCHECK_EQ(1u, instruction->InputCount()); // only one input currently implemented |
| 1093 | |
| 1094 | // Zero out all other elements first. |
| 1095 | __ xorps(dst, dst); |
| 1096 | |
| 1097 | // Shorthand for any type of zero. |
| 1098 | if (IsZeroBitPattern(instruction->InputAt(0))) { |
| 1099 | return; |
| 1100 | } |
| 1101 | |
| 1102 | // Set required elements. |
| 1103 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1104 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1105 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1106 | case DataType::Type::kInt8: |
| 1107 | case DataType::Type::kUint16: |
| 1108 | case DataType::Type::kInt16: // TODO: up to here, and? |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1109 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1110 | UNREACHABLE(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1111 | case DataType::Type::kInt32: |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1112 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1113 | __ movd(dst, locations->InAt(0).AsRegister<Register>()); |
| 1114 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1115 | case DataType::Type::kInt64: { |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1116 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| Aart Bik | b67f7e2 | 2018-01-18 13:29:19 -0800 | [diff] [blame] | 1117 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1118 | __ xorps(tmp, tmp); |
| 1119 | __ movd(dst, locations->InAt(0).AsRegisterPairLow<Register>()); |
| 1120 | __ movd(tmp, locations->InAt(0).AsRegisterPairHigh<Register>()); |
| 1121 | __ punpckldq(dst, tmp); |
| 1122 | break; |
| 1123 | } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1124 | case DataType::Type::kFloat32: |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1125 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1126 | __ movss(dst, locations->InAt(1).AsFpuRegister<XmmRegister>()); |
| 1127 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1128 | case DataType::Type::kFloat64: |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1129 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1130 | __ movsd(dst, locations->InAt(1).AsFpuRegister<XmmRegister>()); |
| 1131 | break; |
| 1132 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1133 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1134 | UNREACHABLE(); |
| 1135 | } |
| 1136 | } |
| 1137 | |
| Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1138 | // Helper to set up locations for vector accumulations. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1139 | static void CreateVecAccumLocations(ArenaAllocator* allocator, HVecOperation* instruction) { |
| 1140 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
| Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1141 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1142 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1143 | case DataType::Type::kInt8: |
| 1144 | case DataType::Type::kUint16: |
| 1145 | case DataType::Type::kInt16: |
| 1146 | case DataType::Type::kInt32: |
| 1147 | case DataType::Type::kInt64: |
| Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1148 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1149 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1150 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 1151 | locations->SetOut(Location::SameAsFirstInput()); |
| 1152 | break; |
| 1153 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1154 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1155 | UNREACHABLE(); |
| 1156 | } |
| Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1157 | } |
| 1158 | |
| Hans Boehm | f5f56c7 | 2018-07-13 00:05:27 +0000 | [diff] [blame] | 1159 | void LocationsBuilderX86::VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) { |
| 1160 | CreateVecAccumLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
| Hans Boehm | f5f56c7 | 2018-07-13 00:05:27 +0000 | [diff] [blame] | 1163 | void InstructionCodeGeneratorX86::VisitVecMultiplyAccumulate(HVecMultiplyAccumulate* instruction) { |
| 1164 | // TODO: pmaddwd? |
| 1165 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | void LocationsBuilderX86::VisitVecSADAccumulate(HVecSADAccumulate* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1169 | CreateVecAccumLocations(GetGraph()->GetAllocator(), instruction); |
| Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | void InstructionCodeGeneratorX86::VisitVecSADAccumulate(HVecSADAccumulate* instruction) { |
| 1173 | // TODO: psadbw for unsigned? |
| 1174 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1175 | } |
| 1176 | |
| Artem Serov | aaac0e3 | 2018-08-07 00:52:22 +0100 | [diff] [blame] | 1177 | void LocationsBuilderX86::VisitVecDotProd(HVecDotProd* instruction) { |
| 1178 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 1179 | } |
| 1180 | |
| 1181 | void InstructionCodeGeneratorX86::VisitVecDotProd(HVecDotProd* instruction) { |
| 1182 | LOG(FATAL) << "No SIMD for " << instruction->GetId(); |
| 1183 | } |
| 1184 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1185 | // Helper to set up locations for vector memory operations. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1186 | static void CreateVecMemLocations(ArenaAllocator* allocator, |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1187 | HVecMemoryOperation* instruction, |
| 1188 | bool is_load) { |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1189 | LocationSummary* locations = new (allocator) LocationSummary(instruction); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1190 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1191 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1192 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1193 | case DataType::Type::kInt8: |
| 1194 | case DataType::Type::kUint16: |
| 1195 | case DataType::Type::kInt16: |
| 1196 | case DataType::Type::kInt32: |
| 1197 | case DataType::Type::kInt64: |
| 1198 | case DataType::Type::kFloat32: |
| 1199 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1200 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1201 | locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1))); |
| 1202 | if (is_load) { |
| 1203 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1204 | } else { |
| 1205 | locations->SetInAt(2, Location::RequiresFpuRegister()); |
| 1206 | } |
| 1207 | break; |
| 1208 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1209 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1210 | UNREACHABLE(); |
| 1211 | } |
| 1212 | } |
| 1213 | |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1214 | // Helper to construct address for vector memory operations. |
| 1215 | 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] | 1216 | Location base = locations->InAt(0); |
| 1217 | Location index = locations->InAt(1); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1218 | ScaleFactor scale = TIMES_1; |
| 1219 | switch (size) { |
| 1220 | case 2: scale = TIMES_2; break; |
| 1221 | case 4: scale = TIMES_4; break; |
| 1222 | case 8: scale = TIMES_8; break; |
| 1223 | default: break; |
| 1224 | } |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1225 | // Incorporate the string or array offset in the address computation. |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1226 | uint32_t offset = is_string_char_at |
| 1227 | ? mirror::String::ValueOffset().Uint32Value() |
| 1228 | : mirror::Array::DataOffset(size).Uint32Value(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1229 | return CodeGeneratorX86::ArrayAddress(base.AsRegister<Register>(), index, scale, offset); |
| 1230 | } |
| 1231 | |
| 1232 | void LocationsBuilderX86::VisitVecLoad(HVecLoad* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1233 | CreateVecMemLocations(GetGraph()->GetAllocator(), instruction, /*is_load*/ true); |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1234 | // String load requires a temporary for the compressed load. |
| 1235 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 1236 | instruction->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 1237 | } |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | void InstructionCodeGeneratorX86::VisitVecLoad(HVecLoad* instruction) { |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1241 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1242 | size_t size = DataType::Size(instruction->GetPackedType()); |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1243 | Address address = VecAddress(locations, size, instruction->IsStringCharAt()); |
| 1244 | XmmRegister reg = locations->Out().AsFpuRegister<XmmRegister>(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1245 | bool is_aligned16 = instruction->GetAlignment().IsAlignedAt(16); |
| 1246 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 805b631 | 2018-09-05 14:46:06 +0100 | [diff] [blame] | 1247 | case DataType::Type::kInt16: // (short) s.charAt(.) can yield HVecLoad/Int16/StringCharAt. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1248 | case DataType::Type::kUint16: |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1249 | DCHECK_EQ(8u, instruction->GetVectorLength()); |
| 1250 | // Special handling of compressed/uncompressed string load. |
| 1251 | if (mirror::kUseStringCompression && instruction->IsStringCharAt()) { |
| 1252 | NearLabel done, not_compressed; |
| 1253 | XmmRegister tmp = locations->GetTemp(0).AsFpuRegister<XmmRegister>(); |
| 1254 | // Test compression bit. |
| 1255 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1256 | "Expecting 0=compressed, 1=uncompressed"); |
| 1257 | uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 1258 | __ testb(Address(locations->InAt(0).AsRegister<Register>(), count_offset), Immediate(1)); |
| 1259 | __ j(kNotZero, ¬_compressed); |
| 1260 | // Zero extend 8 compressed bytes into 8 chars. |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1261 | __ movsd(reg, VecAddress(locations, 1, instruction->IsStringCharAt())); |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1262 | __ pxor(tmp, tmp); |
| 1263 | __ punpcklbw(reg, tmp); |
| 1264 | __ jmp(&done); |
| 1265 | // Load 4 direct uncompressed chars. |
| 1266 | __ Bind(¬_compressed); |
| 1267 | is_aligned16 ? __ movdqa(reg, address) : __ movdqu(reg, address); |
| 1268 | __ Bind(&done); |
| 1269 | return; |
| 1270 | } |
| 1271 | FALLTHROUGH_INTENDED; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1272 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1273 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1274 | case DataType::Type::kInt8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1275 | case DataType::Type::kInt32: |
| 1276 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1277 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 1278 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 1279 | is_aligned16 ? __ movdqa(reg, address) : __ movdqu(reg, address); |
| 1280 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1281 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1282 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1283 | is_aligned16 ? __ movaps(reg, address) : __ movups(reg, address); |
| 1284 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1285 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1286 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1287 | is_aligned16 ? __ movapd(reg, address) : __ movupd(reg, address); |
| 1288 | break; |
| 1289 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1290 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1291 | UNREACHABLE(); |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | void LocationsBuilderX86::VisitVecStore(HVecStore* instruction) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1296 | CreateVecMemLocations(GetGraph()->GetAllocator(), instruction, /*is_load*/ false); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | void InstructionCodeGeneratorX86::VisitVecStore(HVecStore* instruction) { |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1300 | LocationSummary* locations = instruction->GetLocations(); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1301 | size_t size = DataType::Size(instruction->GetPackedType()); |
| Aart Bik | 472821b | 2017-04-27 17:23:51 -0700 | [diff] [blame] | 1302 | Address address = VecAddress(locations, size, /*is_string_char_at*/ false); |
| 1303 | XmmRegister reg = locations->InAt(2).AsFpuRegister<XmmRegister>(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1304 | bool is_aligned16 = instruction->GetAlignment().IsAlignedAt(16); |
| 1305 | switch (instruction->GetPackedType()) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1306 | case DataType::Type::kBool: |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1307 | case DataType::Type::kUint8: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1308 | case DataType::Type::kInt8: |
| 1309 | case DataType::Type::kUint16: |
| 1310 | case DataType::Type::kInt16: |
| 1311 | case DataType::Type::kInt32: |
| 1312 | case DataType::Type::kInt64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1313 | DCHECK_LE(2u, instruction->GetVectorLength()); |
| 1314 | DCHECK_LE(instruction->GetVectorLength(), 16u); |
| 1315 | is_aligned16 ? __ movdqa(address, reg) : __ movdqu(address, reg); |
| 1316 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1317 | case DataType::Type::kFloat32: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1318 | DCHECK_EQ(4u, instruction->GetVectorLength()); |
| 1319 | is_aligned16 ? __ movaps(address, reg) : __ movups(address, reg); |
| 1320 | break; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1321 | case DataType::Type::kFloat64: |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1322 | DCHECK_EQ(2u, instruction->GetVectorLength()); |
| 1323 | is_aligned16 ? __ movapd(address, reg) : __ movupd(address, reg); |
| 1324 | break; |
| 1325 | default: |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1326 | LOG(FATAL) << "Unsupported SIMD type: " << instruction->GetPackedType(); |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1327 | UNREACHABLE(); |
| 1328 | } |
| 1329 | } |
| 1330 | |
| 1331 | #undef __ |
| 1332 | |
| 1333 | } // namespace x86 |
| 1334 | } // namespace art |