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