1 //===-- X86ShuffleDecode.h - X86 shuffle decode logic -----------*-C++-*---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Define several functions to decode x86 specific shuffle semantics into a
11 // generic vector mask.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
16 #define LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
18 #include "llvm/ADT/APInt.h"
19 #include "llvm/ADT/SmallVector.h"
21 //===----------------------------------------------------------------------===//
22 // Vector Mask Decoding
23 //===----------------------------------------------------------------------===//
26 template <typename T> class ArrayRef;
28 enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 };
30 /// Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.
31 void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
33 // Insert the bottom Len elements from a second source into a vector starting at
35 void DecodeInsertElementMask(unsigned NumElts, unsigned Idx, unsigned Len,
36 SmallVectorImpl<int> &ShuffleMask);
38 /// Decode a MOVHLPS instruction as a v2f64/v4f32 shuffle mask.
39 /// i.e. <3,1> or <6,7,2,3>
40 void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);
42 /// Decode a MOVLHPS instruction as a v2f64/v4f32 shuffle mask.
43 /// i.e. <0,2> or <0,1,4,5>
44 void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);
46 void DecodeMOVSLDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
48 void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
50 void DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
52 void DecodePSLLDQMask(unsigned NumElts, unsigned Imm,
53 SmallVectorImpl<int> &ShuffleMask);
55 void DecodePSRLDQMask(unsigned NumElts, unsigned Imm,
56 SmallVectorImpl<int> &ShuffleMask);
58 void DecodePALIGNRMask(unsigned NumElts, unsigned Imm,
59 SmallVectorImpl<int> &ShuffleMask);
61 void DecodeVALIGNMask(unsigned NumElts, unsigned Imm,
62 SmallVectorImpl<int> &ShuffleMask);
64 /// Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps.
65 /// VT indicates the type of the vector allowing it to handle different
66 /// datatypes and vector widths.
67 void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
68 SmallVectorImpl<int> &ShuffleMask);
70 /// Decodes the shuffle masks for pshufhw.
71 /// VT indicates the type of the vector allowing it to handle different
72 /// datatypes and vector widths.
73 void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm,
74 SmallVectorImpl<int> &ShuffleMask);
76 /// Decodes the shuffle masks for pshuflw.
77 /// VT indicates the type of the vector allowing it to handle different
78 /// datatypes and vector widths.
79 void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm,
80 SmallVectorImpl<int> &ShuffleMask);
82 /// Decodes a PSWAPD 3DNow! instruction.
83 void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
85 /// Decodes the shuffle masks for shufp*.
86 /// VT indicates the type of the vector allowing it to handle different
87 /// datatypes and vector widths.
88 void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
89 SmallVectorImpl<int> &ShuffleMask);
91 /// Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.
92 /// VT indicates the type of the vector allowing it to handle different
93 /// datatypes and vector widths.
94 void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits,
95 SmallVectorImpl<int> &ShuffleMask);
97 /// Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.
98 /// VT indicates the type of the vector allowing it to handle different
99 /// datatypes and vector widths.
100 void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits,
101 SmallVectorImpl<int> &ShuffleMask);
103 /// Decodes a broadcast of the first element of a vector.
104 void DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
106 /// Decodes a broadcast of a subvector to a larger vector type.
107 void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts,
108 SmallVectorImpl<int> &ShuffleMask);
110 /// Decode a PSHUFB mask from a raw array of constants such as from
112 void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
113 SmallVectorImpl<int> &ShuffleMask);
115 /// Decode a BLEND immediate mask into a shuffle mask.
116 void DecodeBLENDMask(unsigned NumElts, unsigned Imm,
117 SmallVectorImpl<int> &ShuffleMask);
119 void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm,
120 SmallVectorImpl<int> &ShuffleMask);
122 /// Decode a shuffle packed values at 128-bit granularity
123 /// immediate mask into a shuffle mask.
124 void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize,
125 unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
127 /// Decodes the shuffle masks for VPERMQ/VPERMPD.
128 void DecodeVPERMMask(unsigned NumElts, unsigned Imm,
129 SmallVectorImpl<int> &ShuffleMask);
131 /// Decode a VPPERM mask from a raw array of constants such as from
133 /// This can only basic masks (permutes + zeros), not any of the other
134 /// operations that VPPERM can perform.
135 void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
136 SmallVectorImpl<int> &ShuffleMask);
138 /// Decode a zero extension instruction as a shuffle mask.
139 void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits,
141 SmallVectorImpl<int> &ShuffleMask);
143 /// Decode a move lower and zero upper instruction as a shuffle mask.
144 void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
146 /// Decode a scalar float move instruction as a shuffle mask.
147 void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad,
148 SmallVectorImpl<int> &ShuffleMask);
150 /// Decode a SSE4A EXTRQ instruction as a shuffle mask.
151 void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,
152 SmallVectorImpl<int> &ShuffleMask);
154 /// Decode a SSE4A INSERTQ instruction as a shuffle mask.
155 void DecodeINSERTQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,
156 SmallVectorImpl<int> &ShuffleMask);
158 /// Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants.
159 void DecodeVPERMILPMask(unsigned NumElts, unsigned ScalarBits,
160 ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
161 SmallVectorImpl<int> &ShuffleMask);
163 /// Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants.
164 void DecodeVPERMIL2PMask(unsigned NumElts, unsigned ScalarBits, unsigned M2Z,
165 ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
166 SmallVectorImpl<int> &ShuffleMask);
168 /// Decode a VPERM W/D/Q/PS/PD mask from a raw array of constants.
169 void DecodeVPERMVMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
170 SmallVectorImpl<int> &ShuffleMask);
172 /// Decode a VPERMT2 W/D/Q/PS/PD mask from a raw array of constants.
173 void DecodeVPERMV3Mask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
174 SmallVectorImpl<int> &ShuffleMask);