LLVM  8.0.1
X86ShuffleDecode.h
Go to the documentation of this file.
1 //===-- X86ShuffleDecode.h - X86 shuffle decode logic -----------*-C++-*---===//
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 #ifndef LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
16 #define LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
17 
18 #include "llvm/ADT/APInt.h"
19 #include "llvm/ADT/SmallVector.h"
20 
21 //===----------------------------------------------------------------------===//
22 // Vector Mask Decoding
23 //===----------------------------------------------------------------------===//
24 
25 namespace llvm {
26 template <typename T> class ArrayRef;
27 
28 enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 };
29 
30 /// Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.
31 void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
32 
33 // Insert the bottom Len elements from a second source into a vector starting at
34 // element Idx.
35 void DecodeInsertElementMask(unsigned NumElts, unsigned Idx, unsigned Len,
36  SmallVectorImpl<int> &ShuffleMask);
37 
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);
41 
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);
45 
46 void DecodeMOVSLDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
47 
48 void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
49 
50 void DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
51 
52 void DecodePSLLDQMask(unsigned NumElts, unsigned Imm,
53  SmallVectorImpl<int> &ShuffleMask);
54 
55 void DecodePSRLDQMask(unsigned NumElts, unsigned Imm,
56  SmallVectorImpl<int> &ShuffleMask);
57 
58 void DecodePALIGNRMask(unsigned NumElts, unsigned Imm,
59  SmallVectorImpl<int> &ShuffleMask);
60 
61 void DecodeVALIGNMask(unsigned NumElts, unsigned Imm,
62  SmallVectorImpl<int> &ShuffleMask);
63 
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);
69 
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);
75 
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);
81 
82 /// Decodes a PSWAPD 3DNow! instruction.
83 void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
84 
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);
90 
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);
96 
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);
102 
103 /// Decodes a broadcast of the first element of a vector.
104 void DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
105 
106 /// Decodes a broadcast of a subvector to a larger vector type.
107 void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts,
108  SmallVectorImpl<int> &ShuffleMask);
109 
110 /// Decode a PSHUFB mask from a raw array of constants such as from
111 /// BUILD_VECTOR.
112 void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
113  SmallVectorImpl<int> &ShuffleMask);
114 
115 /// Decode a BLEND immediate mask into a shuffle mask.
116 void DecodeBLENDMask(unsigned NumElts, unsigned Imm,
117  SmallVectorImpl<int> &ShuffleMask);
118 
119 void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm,
120  SmallVectorImpl<int> &ShuffleMask);
121 
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);
126 
127 /// Decodes the shuffle masks for VPERMQ/VPERMPD.
128 void DecodeVPERMMask(unsigned NumElts, unsigned Imm,
129  SmallVectorImpl<int> &ShuffleMask);
130 
131 /// Decode a VPPERM mask from a raw array of constants such as from
132 /// BUILD_VECTOR.
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);
137 
138 /// Decode a zero extension instruction as a shuffle mask.
139 void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits,
140  unsigned NumDstElts,
141  SmallVectorImpl<int> &ShuffleMask);
142 
143 /// Decode a move lower and zero upper instruction as a shuffle mask.
144 void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
145 
146 /// Decode a scalar float move instruction as a shuffle mask.
147 void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad,
148  SmallVectorImpl<int> &ShuffleMask);
149 
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);
153 
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);
157 
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);
162 
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);
167 
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);
171 
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);
175 } // llvm namespace
176 
177 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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 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 DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Decodes a broadcast of the first element of a vector.
void DecodePSLLDQMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
DecodePSHUFMask - This decodes the shuffle masks for pshufw, pshufd, and vpermilp*.
void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Decode a move lower and zero upper instruction as a shuffle mask.
void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits, SmallVectorImpl< int > &ShuffleMask)
DecodeUNPCKHMask - This decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.
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 DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, SmallVectorImpl< int > &ShuffleMask)
Decode a SSE4A EXTRQ instruction as a shuffle mask.
This file implements a class to represent arbitrary precision integral constant values and operations...
void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
void DecodeVALIGNMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for pshuflw.
void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits, SmallVectorImpl< int > &ShuffleMask)
DecodeUNPCKLMask - This decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.
void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl< int > &ShuffleMask)
Decode a MOVLHPS instruction as a v2f64/v4f32 shuffle mask.
void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits, unsigned NumDstElts, SmallVectorImpl< int > &Mask)
Decode a zero extension instruction as a shuffle mask.
void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.
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 DecodeMOVSLDUPMask(unsigned NumElts, 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 DecodeINSERTQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, SmallVectorImpl< int > &ShuffleMask)
Decode a SSE4A INSERTQ instruction as a shuffle mask.
void DecodeVPERMMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
DecodeVPERMMask - this decodes the shuffle masks for VPERMQ/VPERMPD.
Class for arbitrary precision integers.
Definition: APInt.h:70
void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for pshufhw.
void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad, SmallVectorImpl< int > &Mask)
Decode a scalar float move instruction as a shuffle mask.
void DecodePSRLDQMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
DecodeSHUFPMask - This decodes the shuffle masks for shufp*.
void DecodeInsertElementMask(unsigned NumElts, unsigned Idx, unsigned Len, SmallVectorImpl< int > &ShuffleMask)
void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Decodes a PSWAPD 3DNow! instruction.
void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts, SmallVectorImpl< int > &ShuffleMask)
Decodes a broadcast of a subvector to a larger vector type.
void DecodePALIGNRMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl< int > &ShuffleMask)
Decode a MOVHLPS instruction as a v2f64/v4f32 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 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.