xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/MCTargetDesc/X86ShuffleDecode.h (revision e25152834cdf3b353892835a4f3b157e066a8ed4)
1*5ffd83dbSDimitry Andric //===-- X86ShuffleDecode.h - X86 shuffle decode logic -----------*-C++-*---===//
2*5ffd83dbSDimitry Andric //
3*5ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*5ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*5ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*5ffd83dbSDimitry Andric //
7*5ffd83dbSDimitry Andric //===----------------------------------------------------------------------===//
8*5ffd83dbSDimitry Andric //
9*5ffd83dbSDimitry Andric // Define several functions to decode x86 specific shuffle semantics into a
10*5ffd83dbSDimitry Andric // generic vector mask.
11*5ffd83dbSDimitry Andric //
12*5ffd83dbSDimitry Andric //===----------------------------------------------------------------------===//
13*5ffd83dbSDimitry Andric 
14*5ffd83dbSDimitry Andric #ifndef LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
15*5ffd83dbSDimitry Andric #define LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
16*5ffd83dbSDimitry Andric 
17*5ffd83dbSDimitry Andric #include <cstdint>
18*5ffd83dbSDimitry Andric 
19*5ffd83dbSDimitry Andric //===----------------------------------------------------------------------===//
20*5ffd83dbSDimitry Andric //  Vector Mask Decoding
21*5ffd83dbSDimitry Andric //===----------------------------------------------------------------------===//
22*5ffd83dbSDimitry Andric 
23*5ffd83dbSDimitry Andric namespace llvm {
24*5ffd83dbSDimitry Andric class APInt;
25*5ffd83dbSDimitry Andric template <typename T> class ArrayRef;
26*5ffd83dbSDimitry Andric template <typename T> class SmallVectorImpl;
27*5ffd83dbSDimitry Andric 
28*5ffd83dbSDimitry Andric enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 };
29*5ffd83dbSDimitry Andric 
30*5ffd83dbSDimitry Andric /// Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.
31*5ffd83dbSDimitry Andric void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
32*5ffd83dbSDimitry Andric 
33*5ffd83dbSDimitry Andric // Insert the bottom Len elements from a second source into a vector starting at
34*5ffd83dbSDimitry Andric // element Idx.
35*5ffd83dbSDimitry Andric void DecodeInsertElementMask(unsigned NumElts, unsigned Idx, unsigned Len,
36*5ffd83dbSDimitry Andric                              SmallVectorImpl<int> &ShuffleMask);
37*5ffd83dbSDimitry Andric 
38*5ffd83dbSDimitry Andric /// Decode a MOVHLPS instruction as a v2f64/v4f32 shuffle mask.
39*5ffd83dbSDimitry Andric /// i.e. <3,1> or <6,7,2,3>
40*5ffd83dbSDimitry Andric void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);
41*5ffd83dbSDimitry Andric 
42*5ffd83dbSDimitry Andric /// Decode a MOVLHPS instruction as a v2f64/v4f32 shuffle mask.
43*5ffd83dbSDimitry Andric /// i.e. <0,2> or <0,1,4,5>
44*5ffd83dbSDimitry Andric void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);
45*5ffd83dbSDimitry Andric 
46*5ffd83dbSDimitry Andric void DecodeMOVSLDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
47*5ffd83dbSDimitry Andric 
48*5ffd83dbSDimitry Andric void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
49*5ffd83dbSDimitry Andric 
50*5ffd83dbSDimitry Andric void DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
51*5ffd83dbSDimitry Andric 
52*5ffd83dbSDimitry Andric void DecodePSLLDQMask(unsigned NumElts, unsigned Imm,
53*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
54*5ffd83dbSDimitry Andric 
55*5ffd83dbSDimitry Andric void DecodePSRLDQMask(unsigned NumElts, unsigned Imm,
56*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
57*5ffd83dbSDimitry Andric 
58*5ffd83dbSDimitry Andric void DecodePALIGNRMask(unsigned NumElts, unsigned Imm,
59*5ffd83dbSDimitry Andric                        SmallVectorImpl<int> &ShuffleMask);
60*5ffd83dbSDimitry Andric 
61*5ffd83dbSDimitry Andric void DecodeVALIGNMask(unsigned NumElts, unsigned Imm,
62*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
63*5ffd83dbSDimitry Andric 
64*5ffd83dbSDimitry Andric /// Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps.
65*5ffd83dbSDimitry Andric void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
66*5ffd83dbSDimitry Andric                      SmallVectorImpl<int> &ShuffleMask);
67*5ffd83dbSDimitry Andric 
68*5ffd83dbSDimitry Andric /// Decodes the shuffle masks for pshufhw.
69*5ffd83dbSDimitry Andric void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm,
70*5ffd83dbSDimitry Andric                        SmallVectorImpl<int> &ShuffleMask);
71*5ffd83dbSDimitry Andric 
72*5ffd83dbSDimitry Andric /// Decodes the shuffle masks for pshuflw.
73*5ffd83dbSDimitry Andric void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm,
74*5ffd83dbSDimitry Andric                        SmallVectorImpl<int> &ShuffleMask);
75*5ffd83dbSDimitry Andric 
76*5ffd83dbSDimitry Andric /// Decodes a PSWAPD 3DNow! instruction.
77*5ffd83dbSDimitry Andric void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
78*5ffd83dbSDimitry Andric 
79*5ffd83dbSDimitry Andric /// Decodes the shuffle masks for shufp*.
80*5ffd83dbSDimitry Andric void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
81*5ffd83dbSDimitry Andric                      SmallVectorImpl<int> &ShuffleMask);
82*5ffd83dbSDimitry Andric 
83*5ffd83dbSDimitry Andric /// Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.
84*5ffd83dbSDimitry Andric void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits,
85*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
86*5ffd83dbSDimitry Andric 
87*5ffd83dbSDimitry Andric /// Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.
88*5ffd83dbSDimitry Andric void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits,
89*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
90*5ffd83dbSDimitry Andric 
91*5ffd83dbSDimitry Andric /// Decodes a broadcast of the first element of a vector.
92*5ffd83dbSDimitry Andric void DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
93*5ffd83dbSDimitry Andric 
94*5ffd83dbSDimitry Andric /// Decodes a broadcast of a subvector to a larger vector type.
95*5ffd83dbSDimitry Andric void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts,
96*5ffd83dbSDimitry Andric                               SmallVectorImpl<int> &ShuffleMask);
97*5ffd83dbSDimitry Andric 
98*5ffd83dbSDimitry Andric /// Decode a PSHUFB mask from a raw array of constants such as from
99*5ffd83dbSDimitry Andric /// BUILD_VECTOR.
100*5ffd83dbSDimitry Andric void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
101*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
102*5ffd83dbSDimitry Andric 
103*5ffd83dbSDimitry Andric /// Decode a BLEND immediate mask into a shuffle mask.
104*5ffd83dbSDimitry Andric void DecodeBLENDMask(unsigned NumElts, unsigned Imm,
105*5ffd83dbSDimitry Andric                      SmallVectorImpl<int> &ShuffleMask);
106*5ffd83dbSDimitry Andric 
107*5ffd83dbSDimitry Andric void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm,
108*5ffd83dbSDimitry Andric                           SmallVectorImpl<int> &ShuffleMask);
109*5ffd83dbSDimitry Andric 
110*5ffd83dbSDimitry Andric /// Decode a shuffle packed values at 128-bit granularity
111*5ffd83dbSDimitry Andric /// (SHUFF32x4/SHUFF64x2/SHUFI32x4/SHUFI64x2)
112*5ffd83dbSDimitry Andric /// immediate mask into a shuffle mask.
113*5ffd83dbSDimitry Andric void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize,
114*5ffd83dbSDimitry Andric                                unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
115*5ffd83dbSDimitry Andric 
116*5ffd83dbSDimitry Andric /// Decodes the shuffle masks for VPERMQ/VPERMPD.
117*5ffd83dbSDimitry Andric void DecodeVPERMMask(unsigned NumElts, unsigned Imm,
118*5ffd83dbSDimitry Andric                      SmallVectorImpl<int> &ShuffleMask);
119*5ffd83dbSDimitry Andric 
120*5ffd83dbSDimitry Andric /// Decode a VPPERM mask from a raw array of constants such as from
121*5ffd83dbSDimitry Andric /// BUILD_VECTOR.
122*5ffd83dbSDimitry Andric /// This can only basic masks (permutes + zeros), not any of the other
123*5ffd83dbSDimitry Andric /// operations that VPPERM can perform.
124*5ffd83dbSDimitry Andric void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
125*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
126*5ffd83dbSDimitry Andric 
127*5ffd83dbSDimitry Andric /// Decode a zero extension instruction as a shuffle mask.
128*5ffd83dbSDimitry Andric void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits,
129*5ffd83dbSDimitry Andric                           unsigned NumDstElts, bool IsAnyExtend,
130*5ffd83dbSDimitry Andric                           SmallVectorImpl<int> &ShuffleMask);
131*5ffd83dbSDimitry Andric 
132*5ffd83dbSDimitry Andric /// Decode a move lower and zero upper instruction as a shuffle mask.
133*5ffd83dbSDimitry Andric void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
134*5ffd83dbSDimitry Andric 
135*5ffd83dbSDimitry Andric /// Decode a scalar float move instruction as a shuffle mask.
136*5ffd83dbSDimitry Andric void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad,
137*5ffd83dbSDimitry Andric                           SmallVectorImpl<int> &ShuffleMask);
138*5ffd83dbSDimitry Andric 
139*5ffd83dbSDimitry Andric /// Decode a SSE4A EXTRQ instruction as a shuffle mask.
140*5ffd83dbSDimitry Andric void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,
141*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
142*5ffd83dbSDimitry Andric 
143*5ffd83dbSDimitry Andric /// Decode a SSE4A INSERTQ instruction as a shuffle mask.
144*5ffd83dbSDimitry Andric void DecodeINSERTQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,
145*5ffd83dbSDimitry Andric                         SmallVectorImpl<int> &ShuffleMask);
146*5ffd83dbSDimitry Andric 
147*5ffd83dbSDimitry Andric /// Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants.
148*5ffd83dbSDimitry Andric void DecodeVPERMILPMask(unsigned NumElts, unsigned ScalarBits,
149*5ffd83dbSDimitry Andric                         ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
150*5ffd83dbSDimitry Andric                         SmallVectorImpl<int> &ShuffleMask);
151*5ffd83dbSDimitry Andric 
152*5ffd83dbSDimitry Andric /// Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants.
153*5ffd83dbSDimitry Andric void DecodeVPERMIL2PMask(unsigned NumElts, unsigned ScalarBits, unsigned M2Z,
154*5ffd83dbSDimitry Andric                          ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
155*5ffd83dbSDimitry Andric                          SmallVectorImpl<int> &ShuffleMask);
156*5ffd83dbSDimitry Andric 
157*5ffd83dbSDimitry Andric /// Decode a VPERM W/D/Q/PS/PD mask from a raw array of constants.
158*5ffd83dbSDimitry Andric void DecodeVPERMVMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
159*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
160*5ffd83dbSDimitry Andric 
161*5ffd83dbSDimitry Andric /// Decode a VPERMT2 W/D/Q/PS/PD mask from a raw array of constants.
162*5ffd83dbSDimitry Andric void DecodeVPERMV3Mask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
163*5ffd83dbSDimitry Andric                       SmallVectorImpl<int> &ShuffleMask);
164*5ffd83dbSDimitry Andric } // llvm namespace
165*5ffd83dbSDimitry Andric 
166*5ffd83dbSDimitry Andric #endif
167