35 unsigned ZMask = Imm & 15;
36 unsigned CountD = (Imm >> 4) & 3;
37 unsigned CountS = SrcIsMem ? 0 : (Imm >> 6) & 3;
40 unsigned InVal = 4 + CountS;
42 ShuffleMask[CountD] = InVal;
52 assert((
Idx + Len) <= NumElts &&
"Insertion out of range");
54 for (
unsigned i = 0; i != NumElts; ++i)
56 for (
unsigned i = 0; i != Len; ++i)
57 ShuffleMask[
Idx + i] = NumElts + i;
62 for (
unsigned i = NElts / 2; i != NElts; ++i)
65 for (
unsigned i = NElts / 2; i != NElts; ++i)
71 for (
unsigned i = 0; i != NElts / 2; ++i)
74 for (
unsigned i = 0; i != NElts / 2; ++i)
79 for (
int i = 0, e = NumElts / 2; i < e; ++i) {
86 for (
int i = 0, e = NumElts / 2; i < e; ++i) {
93 const unsigned NumLaneElts = 2;
95 for (
unsigned l = 0; l < NumElts; l += NumLaneElts)
96 for (
unsigned i = 0; i < NumLaneElts; ++i)
102 const unsigned NumLaneElts = 16;
104 for (
unsigned l = 0; l < NumElts; l += NumLaneElts)
105 for (
unsigned i = 0; i < NumLaneElts; ++i) {
107 if (i >= Imm) M = i - Imm + l;
114 const unsigned NumLaneElts = 16;
116 for (
unsigned l = 0; l < NumElts; l += NumLaneElts)
117 for (
unsigned i = 0; i < NumLaneElts; ++i) {
118 unsigned Base = i + Imm;
127 const unsigned NumLaneElts = 16;
129 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
130 for (
unsigned i = 0; i != NumLaneElts; ++i) {
131 unsigned Base = i + Imm;
133 if (
Base >= NumLaneElts)
Base += NumElts - NumLaneElts;
143 Imm = Imm & (NumElts - 1);
144 for (
unsigned i = 0; i != NumElts; ++i)
150 unsigned Size = NumElts * ScalarBits;
151 unsigned NumLanes =
Size / 128;
152 if (NumLanes == 0) NumLanes = 1;
153 unsigned NumLaneElts = NumElts / NumLanes;
155 uint32_t SplatImm = (Imm & 0xff) * 0x01010101;
156 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
157 for (
unsigned i = 0; i != NumLaneElts; ++i) {
158 ShuffleMask.
push_back(SplatImm % NumLaneElts + l);
159 SplatImm /= NumLaneElts;
166 for (
unsigned l = 0; l != NumElts; l += 8) {
167 unsigned NewImm = Imm;
168 for (
unsigned i = 0, e = 4; i != e; ++i) {
171 for (
unsigned i = 4, e = 8; i != e; ++i) {
172 ShuffleMask.
push_back(l + 4 + (NewImm & 3));
180 for (
unsigned l = 0; l != NumElts; l += 8) {
181 unsigned NewImm = Imm;
182 for (
unsigned i = 0, e = 4; i != e; ++i) {
186 for (
unsigned i = 4, e = 8; i != e; ++i) {
193 unsigned NumHalfElts = NumElts / 2;
195 for (
unsigned l = 0; l != NumHalfElts; ++l)
197 for (
unsigned h = 0; h != NumHalfElts; ++h)
203 unsigned NumLaneElts = 128 / ScalarBits;
205 unsigned NewImm = Imm;
206 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
208 for (
unsigned s = 0; s != NumElts * 2; s += NumElts) {
209 for (
unsigned i = 0; i != NumLaneElts / 2; ++i) {
210 ShuffleMask.
push_back(NewImm % NumLaneElts + s + l);
211 NewImm /= NumLaneElts;
214 if (NumLaneElts == 4) NewImm = Imm;
222 unsigned NumLanes = (NumElts * ScalarBits) / 128;
223 if (NumLanes == 0) NumLanes = 1;
224 unsigned NumLaneElts = NumElts / NumLanes;
226 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
227 for (
unsigned i = l + NumLaneElts / 2, e = l + NumLaneElts; i != e; ++i) {
238 unsigned NumLanes = (NumElts * ScalarBits) / 128;
239 if (NumLanes == 0 ) NumLanes = 1;
240 unsigned NumLaneElts = NumElts / NumLanes;
242 for (
unsigned l = 0; l != NumElts; l += NumLaneElts) {
243 for (
unsigned i = l, e = l + NumLaneElts / 2; i != e; ++i) {
252 ShuffleMask.
append(NumElts, 0);
257 unsigned Scale = DstNumElts / SrcNumElts;
259 for (
unsigned i = 0; i != Scale; ++i)
260 for (
unsigned j = 0; j != SrcNumElts; ++j)
267 unsigned NumElementsInLane = 128 / ScalarSize;
268 unsigned NumLanes = NumElts / NumElementsInLane;
270 for (
unsigned l = 0; l != NumElts; l += NumElementsInLane) {
271 unsigned Index = (Imm % NumLanes) * NumElementsInLane;
274 if (l >= (NumElts / 2))
276 for (
unsigned i = 0; i != NumElementsInLane; ++i)
283 unsigned HalfSize = NumElts / 2;
285 for (
unsigned l = 0; l != 2; ++l) {
286 unsigned HalfMask = Imm >> (l * 4);
287 unsigned HalfBegin = (HalfMask & 0x3) * HalfSize;
288 for (
unsigned i = HalfBegin, e = HalfBegin + HalfSize; i != e; ++i)
295 for (
int i = 0, e = RawMask.
size(); i < e; ++i) {
303 int Base = (i / 16) * 16;
317 for (
unsigned i = 0; i < NumElts; ++i) {
320 unsigned Bit = i % 8;
321 ShuffleMask.
push_back(((Imm >> Bit) & 1) ? NumElts + i : i);
327 assert(RawMask.
size() == 16 &&
"Illegal VPPERM shuffle mask size");
342 for (
int i = 0, e = RawMask.
size(); i < e; ++i) {
349 uint64_t PermuteOp = (M >> 5) & 0x7;
350 if (PermuteOp == 4) {
354 if (PermuteOp != 0) {
366 for (
unsigned l = 0; l != NumElts; l += 4)
367 for (
unsigned i = 0; i != 4; ++i)
368 ShuffleMask.
push_back(l + ((Imm >> (2 * i)) & 3));
372 unsigned NumDstElts,
bool IsAnyExtend,
374 unsigned Scale = DstScalarBits / SrcScalarBits;
375 assert(SrcScalarBits < DstScalarBits &&
376 "Expected zero extension mask to increase scalar size");
379 for (
unsigned i = 0; i != NumDstElts; i++) {
396 for (
unsigned i = 1; i < NumElts; i++)
402 unsigned HalfElts = NumElts / 2;
410 if (0 != (Len % EltSize) || 0 != (
Idx % EltSize))
418 if ((Len +
Idx) > 64) {
429 for (
int i = 0; i != Len; ++i)
431 for (
int i = Len; i != (int)HalfElts; ++i)
433 for (
int i = HalfElts; i != (int)NumElts; ++i)
439 unsigned HalfElts = NumElts / 2;
447 if (0 != (Len % EltSize) || 0 != (
Idx % EltSize))
455 if ((Len +
Idx) > 64) {
467 for (
int i = 0; i !=
Idx; ++i)
469 for (
int i = 0; i != Len; ++i)
471 for (
int i =
Idx + Len; i != (int)HalfElts; ++i)
473 for (
int i = HalfElts; i != (int)NumElts; ++i)
480 unsigned VecSize = NumElts * ScalarBits;
481 unsigned NumLanes = VecSize / 128;
482 unsigned NumEltsPerLane = NumElts / NumLanes;
483 assert((VecSize == 128 || VecSize == 256 || VecSize == 512) &&
484 "Unexpected vector size");
485 assert((ScalarBits == 32 || ScalarBits == 64) &&
"Unexpected element size");
487 for (
unsigned i = 0, e = RawMask.
size(); i < e; ++i) {
493 M = (ScalarBits == 64 ? ((M >> 1) & 0x1) : (M & 0x3));
494 unsigned LaneOffset = i & ~(NumEltsPerLane - 1);
495 ShuffleMask.
push_back((
int)(LaneOffset + M));
502 unsigned VecSize = NumElts * ScalarBits;
503 unsigned NumLanes = VecSize / 128;
504 unsigned NumEltsPerLane = NumElts / NumLanes;
505 assert((VecSize == 128 || VecSize == 256) &&
"Unexpected vector size");
506 assert((ScalarBits == 32 || ScalarBits == 64) &&
"Unexpected element size");
507 assert((NumElts == RawMask.
size()) &&
"Unexpected mask size");
509 for (
unsigned i = 0, e = RawMask.
size(); i < e; ++i) {
520 unsigned MatchBit = (Selector >> 3) & 0x1;
528 if ((M2Z & 0x2) != 0 && MatchBit != (M2Z & 0x1)) {
533 int Index = i & ~(NumEltsPerLane - 1);
534 if (ScalarBits == 64)
535 Index += (Selector >> 1) & 0x1;
537 Index += Selector & 0x3;
539 int Src = (Selector >> 2) & 0x1;
540 Index += Src * NumElts;
548 for (
int i = 0, e = RawMask.
size(); i != e; ++i) {
562 for (
int i = 0, e = RawMask.
size(); i != e; ++i) {
This file implements a class to represent arbitrary precision integral constant values and operations...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is an optimization pass for GlobalISel generic memory operations.
void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits, unsigned NumDstElts, bool IsAnyExtend, SmallVectorImpl< int > &ShuffleMask)
Decode a zero extension instruction as a shuffle mask.
void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl< int > &ShuffleMask)
Decode a MOVHLPS instruction as a v2f64/v4f32 shuffle mask.
void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Decode a move lower and zero upper instruction as a shuffle mask.
void DecodeInsertElementMask(unsigned NumElts, unsigned Idx, unsigned Len, SmallVectorImpl< int > &ShuffleMask)
void DecodeVPERMILPMask(unsigned NumElts, unsigned ScalarBits, ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants.
void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for pshuflw.
void DecodeVPERMV3Mask(ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPERMT2 W/D/Q/PS/PD mask from a raw array of constants.
void DecodeBLENDMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decode a BLEND immediate mask into a shuffle mask.
void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decode a shuffle packed values at 128-bit granularity (SHUFF32x4/SHUFF64x2/SHUFI32x4/SHUFI64x2) immed...
void DecodeVPERMMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for VPERMQ/VPERMPD.
void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, SmallVectorImpl< int > &ShuffleMask)
Decode a SSE4A EXTRQ instruction as a shuffle mask.
void DecodePSRLDQMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl< int > &ShuffleMask, bool SrcIsMem)
Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.
void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodeVPERMIL2PMask(unsigned NumElts, unsigned ScalarBits, unsigned M2Z, ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants.
void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl< int > &ShuffleMask)
Decode a MOVLHPS instruction as a v2f64/v4f32 shuffle mask.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Decodes a PSWAPD 3DNow! instruction.
void DecodeINSERTQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, SmallVectorImpl< int > &ShuffleMask)
Decode a SSE4A INSERTQ instruction as a shuffle mask.
void DecodeVPERMVMask(ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPERM W/D/Q/PS/PD mask from a raw array of constants.
void DecodeVALIGNMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad, SmallVectorImpl< int > &ShuffleMask)
Decode a scalar float move instruction as a shuffle mask.
void DecodeVPPERMMask(ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a VPPERM mask from a raw array of constants such as from BUILD_VECTOR.
void DecodePALIGNRMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodeMOVSLDUPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts, SmallVectorImpl< int > &ShuffleMask)
Decodes a broadcast of a subvector to a larger vector type.
void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.
void DecodePSLLDQMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.
void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps.
void DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
void DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Decodes a broadcast of the first element of a vector.
void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for shufp*.
void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for pshufhw.
void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
void DecodePSHUFBMask(ArrayRef< uint64_t > RawMask, const APInt &UndefElts, SmallVectorImpl< int > &ShuffleMask)
Decode a PSHUFB mask from a raw array of constants such as from BUILD_VECTOR.