NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 1 | //===-- X86ShuffleDecode.cpp - X86 shuffle decode logic -------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Define several functions to decode x86 specific shuffle semantics into a |
| 11 | // generic vector mask. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "X86ShuffleDecode.h" |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/ArrayRef.h" |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 17 | |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | // Vector Mask Decoding |
| 20 | //===----------------------------------------------------------------------===// |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask) { |
| 25 | // Defaults the copying the dest value. |
| 26 | ShuffleMask.push_back(0); |
| 27 | ShuffleMask.push_back(1); |
| 28 | ShuffleMask.push_back(2); |
| 29 | ShuffleMask.push_back(3); |
| 30 | |
| 31 | // Decode the immediate. |
| 32 | unsigned ZMask = Imm & 15; |
| 33 | unsigned CountD = (Imm >> 4) & 3; |
| 34 | unsigned CountS = (Imm >> 6) & 3; |
| 35 | |
| 36 | // CountS selects which input element to use. |
NAKAMURA Takumi | 5582a6a | 2015-05-25 01:43:34 +0000 | [diff] [blame] | 37 | unsigned InVal = 4 + CountS; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 38 | // CountD specifies which element of destination to update. |
| 39 | ShuffleMask[CountD] = InVal; |
| 40 | // ZMask zaps values, potentially overriding the CountD elt. |
| 41 | if (ZMask & 1) ShuffleMask[0] = SM_SentinelZero; |
| 42 | if (ZMask & 2) ShuffleMask[1] = SM_SentinelZero; |
| 43 | if (ZMask & 4) ShuffleMask[2] = SM_SentinelZero; |
| 44 | if (ZMask & 8) ShuffleMask[3] = SM_SentinelZero; |
| 45 | } |
| 46 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 47 | void DecodeInsertElementMask(unsigned NumElts, unsigned Idx, unsigned Len, |
Simon Pilgrim | a3d6744 | 2016-02-07 15:39:22 +0000 | [diff] [blame] | 48 | SmallVectorImpl<int> &ShuffleMask) { |
Simon Pilgrim | a3d6744 | 2016-02-07 15:39:22 +0000 | [diff] [blame] | 49 | assert((Idx + Len) <= NumElts && "Insertion out of range"); |
| 50 | |
| 51 | for (unsigned i = 0; i != NumElts; ++i) |
| 52 | ShuffleMask.push_back(i); |
| 53 | for (unsigned i = 0; i != Len; ++i) |
| 54 | ShuffleMask[Idx + i] = NumElts + i; |
| 55 | } |
| 56 | |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 57 | // <3,1> or <6,7,2,3> |
| 58 | void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask) { |
NAKAMURA Takumi | 5582a6a | 2015-05-25 01:43:34 +0000 | [diff] [blame] | 59 | for (unsigned i = NElts / 2; i != NElts; ++i) |
| 60 | ShuffleMask.push_back(NElts + i); |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 61 | |
NAKAMURA Takumi | 5582a6a | 2015-05-25 01:43:34 +0000 | [diff] [blame] | 62 | for (unsigned i = NElts / 2; i != NElts; ++i) |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 63 | ShuffleMask.push_back(i); |
| 64 | } |
| 65 | |
| 66 | // <0,2> or <0,1,4,5> |
| 67 | void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask) { |
NAKAMURA Takumi | 5582a6a | 2015-05-25 01:43:34 +0000 | [diff] [blame] | 68 | for (unsigned i = 0; i != NElts / 2; ++i) |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 69 | ShuffleMask.push_back(i); |
| 70 | |
NAKAMURA Takumi | 5582a6a | 2015-05-25 01:43:34 +0000 | [diff] [blame] | 71 | for (unsigned i = 0; i != NElts / 2; ++i) |
| 72 | ShuffleMask.push_back(NElts + i); |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 75 | void DecodeMOVSLDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 76 | for (int i = 0, e = NumElts / 2; i < e; ++i) { |
| 77 | ShuffleMask.push_back(2 * i); |
| 78 | ShuffleMask.push_back(2 * i); |
| 79 | } |
| 80 | } |
| 81 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 82 | void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 83 | for (int i = 0, e = NumElts / 2; i < e; ++i) { |
| 84 | ShuffleMask.push_back(2 * i + 1); |
| 85 | ShuffleMask.push_back(2 * i + 1); |
| 86 | } |
| 87 | } |
| 88 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 89 | void DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask) { |
| 90 | const unsigned NumLaneElts = 2; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 91 | |
| 92 | for (unsigned l = 0; l < NumElts; l += NumLaneElts) |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 93 | for (unsigned i = 0; i < NumLaneElts; ++i) |
| 94 | ShuffleMask.push_back(l); |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 97 | void DecodePSLLDQMask(unsigned NumElts, unsigned Imm, |
| 98 | SmallVectorImpl<int> &ShuffleMask) { |
| 99 | const unsigned NumLaneElts = 16; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 100 | |
| 101 | for (unsigned l = 0; l < NumElts; l += NumLaneElts) |
| 102 | for (unsigned i = 0; i < NumLaneElts; ++i) { |
| 103 | int M = SM_SentinelZero; |
| 104 | if (i >= Imm) M = i - Imm + l; |
| 105 | ShuffleMask.push_back(M); |
| 106 | } |
| 107 | } |
| 108 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 109 | void DecodePSRLDQMask(unsigned NumElts, unsigned Imm, |
| 110 | SmallVectorImpl<int> &ShuffleMask) { |
| 111 | const unsigned NumLaneElts = 16; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 112 | |
| 113 | for (unsigned l = 0; l < NumElts; l += NumLaneElts) |
| 114 | for (unsigned i = 0; i < NumLaneElts; ++i) { |
| 115 | unsigned Base = i + Imm; |
| 116 | int M = Base + l; |
| 117 | if (Base >= NumLaneElts) M = SM_SentinelZero; |
| 118 | ShuffleMask.push_back(M); |
| 119 | } |
| 120 | } |
| 121 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 122 | void DecodePALIGNRMask(unsigned NumElts, unsigned Imm, |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 123 | SmallVectorImpl<int> &ShuffleMask) { |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 124 | const unsigned NumLaneElts = 16; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 125 | |
| 126 | for (unsigned l = 0; l != NumElts; l += NumLaneElts) { |
| 127 | for (unsigned i = 0; i != NumLaneElts; ++i) { |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 128 | unsigned Base = i + Imm; |
| 129 | // if i+imm is out of this lane then we actually need the other source |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 130 | if (Base >= NumLaneElts) Base += NumElts - NumLaneElts; |
| 131 | ShuffleMask.push_back(Base + l); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 136 | void DecodeVALIGNMask(unsigned NumElts, unsigned Imm, |
Craig Topper | b084c90 | 2016-10-22 06:51:56 +0000 | [diff] [blame] | 137 | SmallVectorImpl<int> &ShuffleMask) { |
Craig Topper | b084c90 | 2016-10-22 06:51:56 +0000 | [diff] [blame] | 138 | // Not all bits of the immediate are used so mask it. |
| 139 | assert(isPowerOf2_32(NumElts) && "NumElts should be power of 2"); |
| 140 | Imm = Imm & (NumElts - 1); |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 141 | for (unsigned i = 0; i != NumElts; ++i) |
Craig Topper | b084c90 | 2016-10-22 06:51:56 +0000 | [diff] [blame] | 142 | ShuffleMask.push_back(i + Imm); |
| 143 | } |
| 144 | |
Simon Pilgrim | f8f86ab | 2015-09-13 11:28:45 +0000 | [diff] [blame] | 145 | /// DecodePSHUFMask - This decodes the shuffle masks for pshufw, pshufd, and vpermilp*. |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 146 | /// VT indicates the type of the vector allowing it to handle different |
| 147 | /// datatypes and vector widths. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 148 | void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm, |
| 149 | SmallVectorImpl<int> &ShuffleMask) { |
| 150 | unsigned Size = NumElts * ScalarBits; |
| 151 | unsigned NumLanes = Size / 128; |
Simon Pilgrim | f8f86ab | 2015-09-13 11:28:45 +0000 | [diff] [blame] | 152 | if (NumLanes == 0) NumLanes = 1; // Handle MMX |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 153 | unsigned NumLaneElts = NumElts / NumLanes; |
| 154 | |
Craig Topper | 2ed4328 | 2018-06-08 01:09:31 +0000 | [diff] [blame^] | 155 | uint32_t SplatImm = (Imm & 0xff) * 0x01010101; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 156 | for (unsigned l = 0; l != NumElts; l += NumLaneElts) { |
| 157 | for (unsigned i = 0; i != NumLaneElts; ++i) { |
Craig Topper | 2ed4328 | 2018-06-08 01:09:31 +0000 | [diff] [blame^] | 158 | ShuffleMask.push_back(SplatImm % NumLaneElts + l); |
| 159 | SplatImm /= NumLaneElts; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 160 | } |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 164 | void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm, |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 165 | SmallVectorImpl<int> &ShuffleMask) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 166 | for (unsigned l = 0; l != NumElts; l += 8) { |
| 167 | unsigned NewImm = Imm; |
| 168 | for (unsigned i = 0, e = 4; i != e; ++i) { |
| 169 | ShuffleMask.push_back(l + i); |
| 170 | } |
| 171 | for (unsigned i = 4, e = 8; i != e; ++i) { |
| 172 | ShuffleMask.push_back(l + 4 + (NewImm & 3)); |
| 173 | NewImm >>= 2; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 178 | void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm, |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 179 | SmallVectorImpl<int> &ShuffleMask) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 180 | for (unsigned l = 0; l != NumElts; l += 8) { |
| 181 | unsigned NewImm = Imm; |
| 182 | for (unsigned i = 0, e = 4; i != e; ++i) { |
| 183 | ShuffleMask.push_back(l + (NewImm & 3)); |
| 184 | NewImm >>= 2; |
| 185 | } |
| 186 | for (unsigned i = 4, e = 8; i != e; ++i) { |
| 187 | ShuffleMask.push_back(l + i); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 192 | void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask) { |
Simon Pilgrim | f8f86ab | 2015-09-13 11:28:45 +0000 | [diff] [blame] | 193 | unsigned NumHalfElts = NumElts / 2; |
| 194 | |
| 195 | for (unsigned l = 0; l != NumHalfElts; ++l) |
| 196 | ShuffleMask.push_back(l + NumHalfElts); |
| 197 | for (unsigned h = 0; h != NumHalfElts; ++h) |
| 198 | ShuffleMask.push_back(h); |
| 199 | } |
| 200 | |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 201 | /// DecodeSHUFPMask - This decodes the shuffle masks for shufp*. VT indicates |
| 202 | /// the type of the vector allowing it to handle different datatypes and vector |
| 203 | /// widths. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 204 | void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, |
| 205 | unsigned Imm, SmallVectorImpl<int> &ShuffleMask) { |
| 206 | unsigned NumLaneElts = 128 / ScalarBits; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 207 | |
| 208 | unsigned NewImm = Imm; |
| 209 | for (unsigned l = 0; l != NumElts; l += NumLaneElts) { |
| 210 | // each half of a lane comes from different source |
NAKAMURA Takumi | 5582a6a | 2015-05-25 01:43:34 +0000 | [diff] [blame] | 211 | for (unsigned s = 0; s != NumElts * 2; s += NumElts) { |
| 212 | for (unsigned i = 0; i != NumLaneElts / 2; ++i) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 213 | ShuffleMask.push_back(NewImm % NumLaneElts + s + l); |
| 214 | NewImm /= NumLaneElts; |
| 215 | } |
| 216 | } |
| 217 | if (NumLaneElts == 4) NewImm = Imm; // reload imm |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /// DecodeUNPCKHMask - This decodes the shuffle masks for unpckhps/unpckhpd |
| 222 | /// and punpckh*. VT indicates the type of the vector allowing it to handle |
| 223 | /// different datatypes and vector widths. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 224 | void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits, |
| 225 | SmallVectorImpl<int> &ShuffleMask) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 226 | // Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate |
| 227 | // independently on 128-bit lanes. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 228 | unsigned NumLanes = (NumElts * ScalarBits) / 128; |
Simon Pilgrim | f8f86ab | 2015-09-13 11:28:45 +0000 | [diff] [blame] | 229 | if (NumLanes == 0) NumLanes = 1; // Handle MMX |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 230 | unsigned NumLaneElts = NumElts / NumLanes; |
| 231 | |
| 232 | for (unsigned l = 0; l != NumElts; l += NumLaneElts) { |
NAKAMURA Takumi | 5582a6a | 2015-05-25 01:43:34 +0000 | [diff] [blame] | 233 | for (unsigned i = l + NumLaneElts / 2, e = l + NumLaneElts; i != e; ++i) { |
| 234 | ShuffleMask.push_back(i); // Reads from dest/src1 |
| 235 | ShuffleMask.push_back(i + NumElts); // Reads from src/src2 |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | /// DecodeUNPCKLMask - This decodes the shuffle masks for unpcklps/unpcklpd |
| 241 | /// and punpckl*. VT indicates the type of the vector allowing it to handle |
| 242 | /// different datatypes and vector widths. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 243 | void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits, |
| 244 | SmallVectorImpl<int> &ShuffleMask) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 245 | // Handle 128 and 256-bit vector lengths. AVX defines UNPCK* to operate |
| 246 | // independently on 128-bit lanes. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 247 | unsigned NumLanes = (NumElts * ScalarBits) / 128; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 248 | if (NumLanes == 0 ) NumLanes = 1; // Handle MMX |
| 249 | unsigned NumLaneElts = NumElts / NumLanes; |
| 250 | |
| 251 | for (unsigned l = 0; l != NumElts; l += NumLaneElts) { |
NAKAMURA Takumi | 5582a6a | 2015-05-25 01:43:34 +0000 | [diff] [blame] | 252 | for (unsigned i = l, e = l + NumLaneElts / 2; i != e; ++i) { |
| 253 | ShuffleMask.push_back(i); // Reads from dest/src1 |
| 254 | ShuffleMask.push_back(i + NumElts); // Reads from src/src2 |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
Simon Pilgrim | c941f6b | 2016-07-18 17:32:59 +0000 | [diff] [blame] | 259 | /// Decodes a broadcast of the first element of a vector. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 260 | void DecodeVectorBroadcast(unsigned NumElts, |
| 261 | SmallVectorImpl<int> &ShuffleMask) { |
Simon Pilgrim | c941f6b | 2016-07-18 17:32:59 +0000 | [diff] [blame] | 262 | ShuffleMask.append(NumElts, 0); |
| 263 | } |
| 264 | |
Simon Pilgrim | a76a8e5 | 2016-07-14 12:07:43 +0000 | [diff] [blame] | 265 | /// Decodes a broadcast of a subvector to a larger vector type. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 266 | void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts, |
Simon Pilgrim | a76a8e5 | 2016-07-14 12:07:43 +0000 | [diff] [blame] | 267 | SmallVectorImpl<int> &ShuffleMask) { |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 268 | unsigned Scale = DstNumElts / SrcNumElts; |
Simon Pilgrim | a76a8e5 | 2016-07-14 12:07:43 +0000 | [diff] [blame] | 269 | |
| 270 | for (unsigned i = 0; i != Scale; ++i) |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 271 | for (unsigned j = 0; j != SrcNumElts; ++j) |
Simon Pilgrim | a76a8e5 | 2016-07-14 12:07:43 +0000 | [diff] [blame] | 272 | ShuffleMask.push_back(j); |
| 273 | } |
| 274 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 275 | /// Decode a shuffle packed values at 128-bit granularity |
Igor Breger | d7bae45 | 2015-10-15 13:29:07 +0000 | [diff] [blame] | 276 | /// (SHUFF32x4/SHUFF64x2/SHUFI32x4/SHUFI64x2) |
| 277 | /// immediate mask into a shuffle mask. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 278 | void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize, |
| 279 | unsigned Imm, |
| 280 | SmallVectorImpl<int> &ShuffleMask) { |
| 281 | unsigned NumElementsInLane = 128 / ScalarSize; |
| 282 | unsigned NumLanes = NumElts / NumElementsInLane; |
Igor Breger | d7bae45 | 2015-10-15 13:29:07 +0000 | [diff] [blame] | 283 | |
Craig Topper | 2ed4328 | 2018-06-08 01:09:31 +0000 | [diff] [blame^] | 284 | for (unsigned l = 0; l != NumElts; l += NumElementsInLane) { |
| 285 | unsigned Index = (Imm % NumLanes) * NumElementsInLane; |
| 286 | Imm /= NumLanes; // Discard the bits we just used. |
Igor Breger | d7bae45 | 2015-10-15 13:29:07 +0000 | [diff] [blame] | 287 | // We actually need the other source. |
Craig Topper | 2ed4328 | 2018-06-08 01:09:31 +0000 | [diff] [blame^] | 288 | if (l >= (NumElts / 2)) |
| 289 | Index += NumElts; |
Igor Breger | d7bae45 | 2015-10-15 13:29:07 +0000 | [diff] [blame] | 290 | for (unsigned i = 0; i != NumElementsInLane; ++i) |
Craig Topper | 2ed4328 | 2018-06-08 01:09:31 +0000 | [diff] [blame^] | 291 | ShuffleMask.push_back(Index + i); |
Igor Breger | d7bae45 | 2015-10-15 13:29:07 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 295 | void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm, |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 296 | SmallVectorImpl<int> &ShuffleMask) { |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 297 | unsigned HalfSize = NumElts / 2; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 298 | |
| 299 | for (unsigned l = 0; l != 2; ++l) { |
Simon Pilgrim | 40343e6 | 2015-07-06 22:46:46 +0000 | [diff] [blame] | 300 | unsigned HalfMask = Imm >> (l * 4); |
| 301 | unsigned HalfBegin = (HalfMask & 0x3) * HalfSize; |
NAKAMURA Takumi | 5582a6a | 2015-05-25 01:43:34 +0000 | [diff] [blame] | 302 | for (unsigned i = HalfBegin, e = HalfBegin + HalfSize; i != e; ++i) |
Denis Protivensky | b612902 | 2015-07-07 07:48:48 +0000 | [diff] [blame] | 303 | ShuffleMask.push_back(HalfMask & 8 ? SM_SentinelZero : (int)i); |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 307 | void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask, |
| 308 | SmallVectorImpl<int> &ShuffleMask) { |
| 309 | for (int i = 0, e = RawMask.size(); i < e; ++i) { |
| 310 | uint64_t M = RawMask[i]; |
| 311 | if (M == (uint64_t)SM_SentinelUndef) { |
| 312 | ShuffleMask.push_back(M); |
| 313 | continue; |
| 314 | } |
Simon Pilgrim | f33cb61 | 2016-03-03 21:55:01 +0000 | [diff] [blame] | 315 | // For 256/512-bit vectors the base of the shuffle is the 128-bit |
| 316 | // subvector we're inside. |
| 317 | int Base = (i / 16) * 16; |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 318 | // If the high bit (7) of the byte is set, the element is zeroed. |
| 319 | if (M & (1 << 7)) |
| 320 | ShuffleMask.push_back(SM_SentinelZero); |
| 321 | else { |
| 322 | // Only the least significant 4 bits of the byte are used. |
| 323 | int Index = Base + (M & 0xf); |
| 324 | ShuffleMask.push_back(Index); |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 329 | void DecodeBLENDMask(unsigned NumElts, unsigned Imm, |
| 330 | SmallVectorImpl<int> &ShuffleMask) { |
| 331 | for (unsigned i = 0; i < NumElts; ++i) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 332 | // If there are more than 8 elements in the vector, then any immediate blend |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 333 | // mask wraps around. |
| 334 | unsigned Bit = i % 8; |
| 335 | ShuffleMask.push_back(((Imm >> Bit) & 1) ? NumElts + i : i); |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
Simon Pilgrim | fd4b9b0 | 2016-04-16 17:52:07 +0000 | [diff] [blame] | 339 | void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask, |
| 340 | SmallVectorImpl<int> &ShuffleMask) { |
| 341 | assert(RawMask.size() == 16 && "Illegal VPPERM shuffle mask size"); |
| 342 | |
| 343 | // VPPERM Operation |
| 344 | // Bits[4:0] - Byte Index (0 - 31) |
| 345 | // Bits[7:5] - Permute Operation |
| 346 | // |
| 347 | // Permute Operation: |
| 348 | // 0 - Source byte (no logical operation). |
| 349 | // 1 - Invert source byte. |
| 350 | // 2 - Bit reverse of source byte. |
| 351 | // 3 - Bit reverse of inverted source byte. |
| 352 | // 4 - 00h (zero - fill). |
| 353 | // 5 - FFh (ones - fill). |
| 354 | // 6 - Most significant bit of source byte replicated in all bit positions. |
| 355 | // 7 - Invert most significant bit of source byte and replicate in all bit positions. |
| 356 | for (int i = 0, e = RawMask.size(); i < e; ++i) { |
| 357 | uint64_t M = RawMask[i]; |
| 358 | if (M == (uint64_t)SM_SentinelUndef) { |
| 359 | ShuffleMask.push_back(M); |
| 360 | continue; |
| 361 | } |
| 362 | |
Simon Pilgrim | f379a6c | 2016-04-24 15:05:04 +0000 | [diff] [blame] | 363 | uint64_t PermuteOp = (M >> 5) & 0x7; |
Simon Pilgrim | fd4b9b0 | 2016-04-16 17:52:07 +0000 | [diff] [blame] | 364 | if (PermuteOp == 4) { |
| 365 | ShuffleMask.push_back(SM_SentinelZero); |
| 366 | continue; |
| 367 | } |
| 368 | if (PermuteOp != 0) { |
| 369 | ShuffleMask.clear(); |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | uint64_t Index = M & 0x1F; |
| 374 | ShuffleMask.push_back((int)Index); |
| 375 | } |
| 376 | } |
| 377 | |
Simon Pilgrim | a0d7383 | 2016-07-03 18:27:37 +0000 | [diff] [blame] | 378 | /// DecodeVPERMMask - this decodes the shuffle masks for VPERMQ/VPERMPD. |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 379 | void DecodeVPERMMask(unsigned NumElts, unsigned Imm, |
| 380 | SmallVectorImpl<int> &ShuffleMask) { |
Simon Pilgrim | a0d7383 | 2016-07-03 18:27:37 +0000 | [diff] [blame] | 381 | for (unsigned l = 0; l != NumElts; l += 4) |
| 382 | for (unsigned i = 0; i != 4; ++i) |
| 383 | ShuffleMask.push_back(l + ((Imm >> (2 * i)) & 3)); |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 386 | void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits, |
| 387 | unsigned NumDstElts, SmallVectorImpl<int> &Mask) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 388 | unsigned Scale = DstScalarBits / SrcScalarBits; |
| 389 | assert(SrcScalarBits < DstScalarBits && |
| 390 | "Expected zero extension mask to increase scalar size"); |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 391 | |
| 392 | for (unsigned i = 0; i != NumDstElts; i++) { |
| 393 | Mask.push_back(i); |
| 394 | for (unsigned j = 1; j != Scale; j++) |
| 395 | Mask.push_back(SM_SentinelZero); |
| 396 | } |
| 397 | } |
| 398 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 399 | void DecodeZeroMoveLowMask(unsigned NumElts, |
| 400 | SmallVectorImpl<int> &ShuffleMask) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 401 | ShuffleMask.push_back(0); |
| 402 | for (unsigned i = 1; i < NumElts; i++) |
| 403 | ShuffleMask.push_back(SM_SentinelZero); |
| 404 | } |
| 405 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 406 | void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad, |
| 407 | SmallVectorImpl<int> &Mask) { |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 408 | // First element comes from the first element of second source. |
| 409 | // Remaining elements: Load zero extends / Move copies from first source. |
NAKAMURA Takumi | fb3bd71 | 2015-05-25 01:43:23 +0000 | [diff] [blame] | 410 | Mask.push_back(NumElts); |
| 411 | for (unsigned i = 1; i < NumElts; i++) |
| 412 | Mask.push_back(IsLoad ? static_cast<int>(SM_SentinelZero) : i); |
| 413 | } |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 414 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 415 | void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 416 | SmallVectorImpl<int> &ShuffleMask) { |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 417 | unsigned HalfElts = NumElts / 2; |
| 418 | |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 419 | // Only the bottom 6 bits are valid for each immediate. |
| 420 | Len &= 0x3F; |
| 421 | Idx &= 0x3F; |
| 422 | |
| 423 | // We can only decode this bit extraction instruction as a shuffle if both the |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 424 | // length and index work with whole elements. |
| 425 | if (0 != (Len % EltSize) || 0 != (Idx % EltSize)) |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 426 | return; |
| 427 | |
| 428 | // A length of zero is equivalent to a bit length of 64. |
| 429 | if (Len == 0) |
| 430 | Len = 64; |
| 431 | |
| 432 | // If the length + index exceeds the bottom 64 bits the result is undefined. |
| 433 | if ((Len + Idx) > 64) { |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 434 | ShuffleMask.append(NumElts, SM_SentinelUndef); |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 435 | return; |
| 436 | } |
| 437 | |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 438 | // Convert index and index to work with elements. |
| 439 | Len /= EltSize; |
| 440 | Idx /= EltSize; |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 441 | |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 442 | // EXTRQ: Extract Len elements starting from Idx. Zero pad the remaining |
| 443 | // elements of the lower 64-bits. The upper 64-bits are undefined. |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 444 | for (int i = 0; i != Len; ++i) |
| 445 | ShuffleMask.push_back(i + Idx); |
Simon Pilgrim | f809c5f | 2017-07-04 17:42:01 +0000 | [diff] [blame] | 446 | for (int i = Len; i != (int)HalfElts; ++i) |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 447 | ShuffleMask.push_back(SM_SentinelZero); |
Simon Pilgrim | f809c5f | 2017-07-04 17:42:01 +0000 | [diff] [blame] | 448 | for (int i = HalfElts; i != (int)NumElts; ++i) |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 449 | ShuffleMask.push_back(SM_SentinelUndef); |
| 450 | } |
| 451 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 452 | void DecodeINSERTQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 453 | SmallVectorImpl<int> &ShuffleMask) { |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 454 | unsigned HalfElts = NumElts / 2; |
| 455 | |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 456 | // Only the bottom 6 bits are valid for each immediate. |
| 457 | Len &= 0x3F; |
| 458 | Idx &= 0x3F; |
| 459 | |
| 460 | // We can only decode this bit insertion instruction as a shuffle if both the |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 461 | // length and index work with whole elements. |
| 462 | if (0 != (Len % EltSize) || 0 != (Idx % EltSize)) |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 463 | return; |
| 464 | |
| 465 | // A length of zero is equivalent to a bit length of 64. |
| 466 | if (Len == 0) |
| 467 | Len = 64; |
| 468 | |
| 469 | // If the length + index exceeds the bottom 64 bits the result is undefined. |
| 470 | if ((Len + Idx) > 64) { |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 471 | ShuffleMask.append(NumElts, SM_SentinelUndef); |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 472 | return; |
| 473 | } |
| 474 | |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 475 | // Convert index and index to work with elements. |
| 476 | Len /= EltSize; |
| 477 | Idx /= EltSize; |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 478 | |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 479 | // INSERTQ: Extract lowest Len elements from lower half of second source and |
| 480 | // insert over first source starting at Idx element. The upper 64-bits are |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 481 | // undefined. |
| 482 | for (int i = 0; i != Idx; ++i) |
| 483 | ShuffleMask.push_back(i); |
| 484 | for (int i = 0; i != Len; ++i) |
Simon Pilgrim | 9f0a0bd | 2017-07-04 16:53:12 +0000 | [diff] [blame] | 485 | ShuffleMask.push_back(i + NumElts); |
Simon Pilgrim | f809c5f | 2017-07-04 17:42:01 +0000 | [diff] [blame] | 486 | for (int i = Idx + Len; i != (int)HalfElts; ++i) |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 487 | ShuffleMask.push_back(i); |
Simon Pilgrim | f809c5f | 2017-07-04 17:42:01 +0000 | [diff] [blame] | 488 | for (int i = HalfElts; i != (int)NumElts; ++i) |
Simon Pilgrim | d85cae3 | 2015-07-06 20:46:41 +0000 | [diff] [blame] | 489 | ShuffleMask.push_back(SM_SentinelUndef); |
| 490 | } |
| 491 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 492 | void DecodeVPERMILPMask(unsigned NumElts, unsigned ScalarBits, |
| 493 | ArrayRef<uint64_t> RawMask, |
Simon Pilgrim | 40e1a71 | 2016-03-05 22:53:31 +0000 | [diff] [blame] | 494 | SmallVectorImpl<int> &ShuffleMask) { |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 495 | unsigned VecSize = NumElts * ScalarBits; |
Simon Pilgrim | 40e1a71 | 2016-03-05 22:53:31 +0000 | [diff] [blame] | 496 | unsigned NumLanes = VecSize / 128; |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 497 | unsigned NumEltsPerLane = NumElts / NumLanes; |
Simon Pilgrim | 40e1a71 | 2016-03-05 22:53:31 +0000 | [diff] [blame] | 498 | assert((VecSize == 128 || VecSize == 256 || VecSize == 512) && |
| 499 | "Unexpected vector size"); |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 500 | assert((ScalarBits == 32 || ScalarBits == 64) && "Unexpected element size"); |
Simon Pilgrim | 40e1a71 | 2016-03-05 22:53:31 +0000 | [diff] [blame] | 501 | |
| 502 | for (unsigned i = 0, e = RawMask.size(); i < e; ++i) { |
| 503 | uint64_t M = RawMask[i]; |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 504 | M = (ScalarBits == 64 ? ((M >> 1) & 0x1) : (M & 0x3)); |
Simon Pilgrim | 40e1a71 | 2016-03-05 22:53:31 +0000 | [diff] [blame] | 505 | unsigned LaneOffset = i & ~(NumEltsPerLane - 1); |
| 506 | ShuffleMask.push_back((int)(LaneOffset + M)); |
| 507 | } |
| 508 | } |
| 509 | |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 510 | void DecodeVPERMIL2PMask(unsigned NumElts, unsigned ScalarBits, unsigned M2Z, |
| 511 | ArrayRef<uint64_t> RawMask, |
Simon Pilgrim | 64c6de4 | 2016-06-05 15:21:30 +0000 | [diff] [blame] | 512 | SmallVectorImpl<int> &ShuffleMask) { |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 513 | unsigned VecSize = NumElts * ScalarBits; |
Simon Pilgrim | 64c6de4 | 2016-06-05 15:21:30 +0000 | [diff] [blame] | 514 | unsigned NumLanes = VecSize / 128; |
Simon Pilgrim | d5bc5c1 | 2016-12-07 11:19:00 +0000 | [diff] [blame] | 515 | unsigned NumEltsPerLane = NumElts / NumLanes; |
| 516 | assert((VecSize == 128 || VecSize == 256) && "Unexpected vector size"); |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 517 | assert((ScalarBits == 32 || ScalarBits == 64) && "Unexpected element size"); |
Simon Pilgrim | d5bc5c1 | 2016-12-07 11:19:00 +0000 | [diff] [blame] | 518 | assert((NumElts == RawMask.size()) && "Unexpected mask size"); |
Simon Pilgrim | 64c6de4 | 2016-06-05 15:21:30 +0000 | [diff] [blame] | 519 | |
| 520 | for (unsigned i = 0, e = RawMask.size(); i < e; ++i) { |
| 521 | // VPERMIL2 Operation. |
| 522 | // Bits[3] - Match Bit. |
| 523 | // Bits[2:1] - (Per Lane) PD Shuffle Mask. |
| 524 | // Bits[2:0] - (Per Lane) PS Shuffle Mask. |
| 525 | uint64_t Selector = RawMask[i]; |
Filipe Cabecinhas | 6e7d546 | 2016-06-06 10:49:56 +0000 | [diff] [blame] | 526 | unsigned MatchBit = (Selector >> 3) & 0x1; |
Simon Pilgrim | 64c6de4 | 2016-06-05 15:21:30 +0000 | [diff] [blame] | 527 | |
| 528 | // M2Z[0:1] MatchBit |
| 529 | // 0Xb X Source selected by Selector index. |
| 530 | // 10b 0 Source selected by Selector index. |
| 531 | // 10b 1 Zero. |
| 532 | // 11b 0 Zero. |
| 533 | // 11b 1 Source selected by Selector index. |
| 534 | if ((M2Z & 0x2) != 0 && MatchBit != (M2Z & 0x1)) { |
| 535 | ShuffleMask.push_back(SM_SentinelZero); |
| 536 | continue; |
| 537 | } |
| 538 | |
Simon Pilgrim | d5bc5c1 | 2016-12-07 11:19:00 +0000 | [diff] [blame] | 539 | int Index = i & ~(NumEltsPerLane - 1); |
Craig Topper | acaba3b | 2018-03-12 16:43:11 +0000 | [diff] [blame] | 540 | if (ScalarBits == 64) |
Simon Pilgrim | 64c6de4 | 2016-06-05 15:21:30 +0000 | [diff] [blame] | 541 | Index += (Selector >> 1) & 0x1; |
| 542 | else |
| 543 | Index += Selector & 0x3; |
| 544 | |
Simon Pilgrim | d5bc5c1 | 2016-12-07 11:19:00 +0000 | [diff] [blame] | 545 | int Src = (Selector >> 2) & 0x1; |
| 546 | Index += Src * NumElts; |
| 547 | ShuffleMask.push_back(Index); |
Simon Pilgrim | 64c6de4 | 2016-06-05 15:21:30 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
Elena Demikhovsky | e88038f | 2015-09-08 06:38:21 +0000 | [diff] [blame] | 551 | void DecodeVPERMVMask(ArrayRef<uint64_t> RawMask, |
| 552 | SmallVectorImpl<int> &ShuffleMask) { |
Simon Pilgrim | 48adedf | 2016-07-05 18:31:17 +0000 | [diff] [blame] | 553 | uint64_t EltMaskSize = RawMask.size() - 1; |
| 554 | for (auto M : RawMask) { |
| 555 | M &= EltMaskSize; |
Elena Demikhovsky | e88038f | 2015-09-08 06:38:21 +0000 | [diff] [blame] | 556 | ShuffleMask.push_back((int)M); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | void DecodeVPERMV3Mask(ArrayRef<uint64_t> RawMask, |
| 561 | SmallVectorImpl<int> &ShuffleMask) { |
Simon Pilgrim | 253ca34 | 2016-03-06 21:54:52 +0000 | [diff] [blame] | 562 | uint64_t EltMaskSize = (RawMask.size() * 2) - 1; |
| 563 | for (auto M : RawMask) { |
| 564 | M &= EltMaskSize; |
Elena Demikhovsky | e88038f | 2015-09-08 06:38:21 +0000 | [diff] [blame] | 565 | ShuffleMask.push_back((int)M); |
| 566 | } |
| 567 | } |
| 568 | |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 569 | } // llvm namespace |