LLVM  14.0.0git
X86ShuffleDecode.h
Go to the documentation of this file.
1 //===-- X86ShuffleDecode.h - X86 shuffle decode logic -----------*-C++-*---===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Define several functions to decode x86 specific shuffle semantics into a
10 // generic vector mask.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
15 #define LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
16 
17 #include <cstdint>
18 
19 //===----------------------------------------------------------------------===//
20 // Vector Mask Decoding
21 //===----------------------------------------------------------------------===//
22 
23 namespace llvm {
24 class APInt;
25 template <typename T> class ArrayRef;
26 template <typename T> class SmallVectorImpl;
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 void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
66  SmallVectorImpl<int> &ShuffleMask);
67 
68 /// Decodes the shuffle masks for pshufhw.
69 void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm,
70  SmallVectorImpl<int> &ShuffleMask);
71 
72 /// Decodes the shuffle masks for pshuflw.
73 void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm,
74  SmallVectorImpl<int> &ShuffleMask);
75 
76 /// Decodes a PSWAPD 3DNow! instruction.
77 void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
78 
79 /// Decodes the shuffle masks for shufp*.
80 void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
81  SmallVectorImpl<int> &ShuffleMask);
82 
83 /// Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.
84 void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits,
85  SmallVectorImpl<int> &ShuffleMask);
86 
87 /// Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.
88 void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits,
89  SmallVectorImpl<int> &ShuffleMask);
90 
91 /// Decodes a broadcast of the first element of a vector.
92 void DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
93 
94 /// Decodes a broadcast of a subvector to a larger vector type.
95 void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts,
96  SmallVectorImpl<int> &ShuffleMask);
97 
98 /// Decode a PSHUFB mask from a raw array of constants such as from
99 /// BUILD_VECTOR.
100 void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
101  SmallVectorImpl<int> &ShuffleMask);
102 
103 /// Decode a BLEND immediate mask into a shuffle mask.
104 void DecodeBLENDMask(unsigned NumElts, unsigned Imm,
105  SmallVectorImpl<int> &ShuffleMask);
106 
107 void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm,
108  SmallVectorImpl<int> &ShuffleMask);
109 
110 /// Decode a shuffle packed values at 128-bit granularity
111 /// (SHUFF32x4/SHUFF64x2/SHUFI32x4/SHUFI64x2)
112 /// immediate mask into a shuffle mask.
113 void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize,
114  unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
115 
116 /// Decodes the shuffle masks for VPERMQ/VPERMPD.
117 void DecodeVPERMMask(unsigned NumElts, unsigned Imm,
118  SmallVectorImpl<int> &ShuffleMask);
119 
120 /// Decode a VPPERM mask from a raw array of constants such as from
121 /// BUILD_VECTOR.
122 /// This can only basic masks (permutes + zeros), not any of the other
123 /// operations that VPPERM can perform.
124 void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
125  SmallVectorImpl<int> &ShuffleMask);
126 
127 /// Decode a zero extension instruction as a shuffle mask.
128 void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits,
129  unsigned NumDstElts, bool IsAnyExtend,
130  SmallVectorImpl<int> &ShuffleMask);
131 
132 /// Decode a move lower and zero upper instruction as a shuffle mask.
133 void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
134 
135 /// Decode a scalar float move instruction as a shuffle mask.
136 void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad,
137  SmallVectorImpl<int> &ShuffleMask);
138 
139 /// Decode a SSE4A EXTRQ instruction as a shuffle mask.
140 void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,
141  SmallVectorImpl<int> &ShuffleMask);
142 
143 /// Decode a SSE4A INSERTQ instruction as a shuffle mask.
144 void DecodeINSERTQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,
145  SmallVectorImpl<int> &ShuffleMask);
146 
147 /// Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants.
148 void DecodeVPERMILPMask(unsigned NumElts, unsigned ScalarBits,
149  ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
150  SmallVectorImpl<int> &ShuffleMask);
151 
152 /// Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants.
153 void DecodeVPERMIL2PMask(unsigned NumElts, unsigned ScalarBits, unsigned M2Z,
154  ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
155  SmallVectorImpl<int> &ShuffleMask);
156 
157 /// Decode a VPERM W/D/Q/PS/PD mask from a raw array of constants.
158 void DecodeVPERMVMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
159  SmallVectorImpl<int> &ShuffleMask);
160 
161 /// Decode a VPERMT2 W/D/Q/PS/PD mask from a raw array of constants.
162 void DecodeVPERMV3Mask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
163  SmallVectorImpl<int> &ShuffleMask);
164 } // llvm namespace
165 
166 #endif
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::DecodePALIGNRMask
void DecodePALIGNRMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Definition: X86ShuffleDecode.cpp:124
llvm::DecodeEXTRQIMask
void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, SmallVectorImpl< int > &ShuffleMask)
Decode a SSE4A EXTRQ instruction as a shuffle mask.
Definition: X86ShuffleDecode.cpp:399
llvm::DecodeUNPCKHMask
void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.
Definition: X86ShuffleDecode.cpp:217
llvm::DecodeMOVSHDUPMask
void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Definition: X86ShuffleDecode.cpp:84
llvm::DecodePSHUFLWMask
void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for pshuflw.
Definition: X86ShuffleDecode.cpp:177
llvm::DecodeINSERTPSMask
void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.
Definition: X86ShuffleDecode.cpp:26
llvm::DecodeVPERMV3Mask
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.
Definition: X86ShuffleDecode.cpp:558
llvm::DecodeMOVSLDUPMask
void DecodeMOVSLDUPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Definition: X86ShuffleDecode.cpp:77
llvm::SM_SentinelUndef
@ SM_SentinelUndef
Definition: X86ShuffleDecode.h:28
llvm::DecodePSHUFBMask
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.
Definition: X86ShuffleDecode.cpp:292
llvm::DecodePSWAPMask
void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Decodes a PSWAPD 3DNow! instruction.
Definition: X86ShuffleDecode.cpp:191
llvm::DecodePSRLDQMask
void DecodePSRLDQMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Definition: X86ShuffleDecode.cpp:111
llvm::DecodeVPERMMask
void DecodeVPERMMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for VPERMQ/VPERMPD.
Definition: X86ShuffleDecode.cpp:363
llvm::DecodePSHUFHWMask
void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for pshufhw.
Definition: X86ShuffleDecode.cpp:163
llvm::DecodeVPPERMMask
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.
Definition: X86ShuffleDecode.cpp:324
llvm::DecodeMOVDDUPMask
void DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Definition: X86ShuffleDecode.cpp:91
llvm::DecodePSHUFMask
void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps.
Definition: X86ShuffleDecode.cpp:147
llvm::DecodeSHUFPMask
void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for shufp*.
Definition: X86ShuffleDecode.cpp:200
llvm::DecodeInsertElementMask
void DecodeInsertElementMask(unsigned NumElts, unsigned Idx, unsigned Len, SmallVectorImpl< int > &ShuffleMask)
Definition: X86ShuffleDecode.cpp:49
llvm::DecodeVectorBroadcast
void DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Decodes a broadcast of the first element of a vector.
Definition: X86ShuffleDecode.cpp:249
llvm::DecodeSubVectorBroadcast
void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts, SmallVectorImpl< int > &ShuffleMask)
Decodes a broadcast of a subvector to a larger vector type.
Definition: X86ShuffleDecode.cpp:254
llvm::DecodeVPERMILPMask
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.
Definition: X86ShuffleDecode.cpp:476
llvm::DecodeScalarMoveMask
void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad, SmallVectorImpl< int > &ShuffleMask)
Decode a scalar float move instruction as a shuffle mask.
Definition: X86ShuffleDecode.cpp:390
llvm::DecodeMOVHLPSMask
void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl< int > &ShuffleMask)
Decode a MOVHLPS instruction as a v2f64/v4f32 shuffle mask.
Definition: X86ShuffleDecode.cpp:60
llvm::DecodeVPERM2X128Mask
void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Definition: X86ShuffleDecode.cpp:280
llvm::DecodeVPERMVMask
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.
Definition: X86ShuffleDecode.cpp:544
llvm::DecodeMOVLHPSMask
void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl< int > &ShuffleMask)
Decode a MOVLHPS instruction as a v2f64/v4f32 shuffle mask.
Definition: X86ShuffleDecode.cpp:69
llvm::SM_SentinelZero
@ SM_SentinelZero
Definition: X86ShuffleDecode.h:28
llvm::DecodeVPERMIL2PMask
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.
Definition: X86ShuffleDecode.cpp:498
llvm::DecodeINSERTQIMask
void DecodeINSERTQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, SmallVectorImpl< int > &ShuffleMask)
Decode a SSE4A INSERTQ instruction as a shuffle mask.
Definition: X86ShuffleDecode.cpp:436
llvm::DecodePSLLDQMask
void DecodePSLLDQMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Definition: X86ShuffleDecode.cpp:99
llvm::DecodeZeroMoveLowMask
void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl< int > &ShuffleMask)
Decode a move lower and zero upper instruction as a shuffle mask.
Definition: X86ShuffleDecode.cpp:384
llvm::DecodeVALIGNMask
void DecodeVALIGNMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Definition: X86ShuffleDecode.cpp:138
llvm::DecodeBLENDMask
void DecodeBLENDMask(unsigned NumElts, unsigned Imm, SmallVectorImpl< int > &ShuffleMask)
Decode a BLEND immediate mask into a shuffle mask.
Definition: X86ShuffleDecode.cpp:314
llvm::decodeVSHUF64x2FamilyMask
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...
Definition: X86ShuffleDecode.cpp:263
llvm::DecodeUNPCKLMask
void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits, SmallVectorImpl< int > &ShuffleMask)
Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.
Definition: X86ShuffleDecode.cpp:233
llvm::DecodeZeroExtendMask
void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits, unsigned NumDstElts, bool IsAnyExtend, SmallVectorImpl< int > &ShuffleMask)
Decode a zero extension instruction as a shuffle mask.
Definition: X86ShuffleDecode.cpp:370