1*9880d681SAndroid Build Coastguard Worker //===-- X86ShuffleDecode.h - X86 shuffle decode logic -----------*-C++-*---===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // Define several functions to decode x86 specific shuffle semantics into a 11*9880d681SAndroid Build Coastguard Worker // generic vector mask. 12*9880d681SAndroid Build Coastguard Worker // 13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H 16*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallVector.h" 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 21*9880d681SAndroid Build Coastguard Worker // Vector Mask Decoding 22*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Worker namespace llvm { 25*9880d681SAndroid Build Coastguard Worker template <typename T> class ArrayRef; 26*9880d681SAndroid Build Coastguard Worker class MVT; 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 }; 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Worker /// Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask. 31*9880d681SAndroid Build Coastguard Worker void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Worker // Insert the bottom Len elements from a second source into a vector starting at 34*9880d681SAndroid Build Coastguard Worker // element Idx. 35*9880d681SAndroid Build Coastguard Worker void DecodeInsertElementMask(MVT VT, unsigned Idx, unsigned Len, 36*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker /// Decode a MOVHLPS instruction as a v2f64/v4f32 shuffle mask. 39*9880d681SAndroid Build Coastguard Worker /// i.e. <3,1> or <6,7,2,3> 40*9880d681SAndroid Build Coastguard Worker void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask); 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker /// Decode a MOVLHPS instruction as a v2f64/v4f32 shuffle mask. 43*9880d681SAndroid Build Coastguard Worker /// i.e. <0,2> or <0,1,4,5> 44*9880d681SAndroid Build Coastguard Worker void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask); 45*9880d681SAndroid Build Coastguard Worker 46*9880d681SAndroid Build Coastguard Worker void DecodeMOVSLDUPMask(MVT VT, SmallVectorImpl<int> &ShuffleMask); 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker void DecodeMOVSHDUPMask(MVT VT, SmallVectorImpl<int> &ShuffleMask); 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Worker void DecodeMOVDDUPMask(MVT VT, SmallVectorImpl<int> &ShuffleMask); 51*9880d681SAndroid Build Coastguard Worker 52*9880d681SAndroid Build Coastguard Worker void DecodePSLLDQMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker void DecodePSRLDQMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Worker void DecodePALIGNRMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Worker /// Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps. 59*9880d681SAndroid Build Coastguard Worker /// VT indicates the type of the vector allowing it to handle different 60*9880d681SAndroid Build Coastguard Worker /// datatypes and vector widths. 61*9880d681SAndroid Build Coastguard Worker void DecodePSHUFMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 62*9880d681SAndroid Build Coastguard Worker 63*9880d681SAndroid Build Coastguard Worker /// Decodes the shuffle masks for pshufhw. 64*9880d681SAndroid Build Coastguard Worker /// VT indicates the type of the vector allowing it to handle different 65*9880d681SAndroid Build Coastguard Worker /// datatypes and vector widths. 66*9880d681SAndroid Build Coastguard Worker void DecodePSHUFHWMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Worker /// Decodes the shuffle masks for pshuflw. 69*9880d681SAndroid Build Coastguard Worker /// VT indicates the type of the vector allowing it to handle different 70*9880d681SAndroid Build Coastguard Worker /// datatypes and vector widths. 71*9880d681SAndroid Build Coastguard Worker void DecodePSHUFLWMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 72*9880d681SAndroid Build Coastguard Worker 73*9880d681SAndroid Build Coastguard Worker /// Decodes a PSWAPD 3DNow! instruction. 74*9880d681SAndroid Build Coastguard Worker void DecodePSWAPMask(MVT VT, SmallVectorImpl<int> &ShuffleMask); 75*9880d681SAndroid Build Coastguard Worker 76*9880d681SAndroid Build Coastguard Worker /// Decodes the shuffle masks for shufp*. 77*9880d681SAndroid Build Coastguard Worker /// VT indicates the type of the vector allowing it to handle different 78*9880d681SAndroid Build Coastguard Worker /// datatypes and vector widths. 79*9880d681SAndroid Build Coastguard Worker void DecodeSHUFPMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Worker /// Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*. 82*9880d681SAndroid Build Coastguard Worker /// VT indicates the type of the vector allowing it to handle different 83*9880d681SAndroid Build Coastguard Worker /// datatypes and vector widths. 84*9880d681SAndroid Build Coastguard Worker void DecodeUNPCKHMask(MVT VT, SmallVectorImpl<int> &ShuffleMask); 85*9880d681SAndroid Build Coastguard Worker 86*9880d681SAndroid Build Coastguard Worker /// Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*. 87*9880d681SAndroid Build Coastguard Worker /// VT indicates the type of the vector allowing it to handle different 88*9880d681SAndroid Build Coastguard Worker /// datatypes and vector widths. 89*9880d681SAndroid Build Coastguard Worker void DecodeUNPCKLMask(MVT VT, SmallVectorImpl<int> &ShuffleMask); 90*9880d681SAndroid Build Coastguard Worker 91*9880d681SAndroid Build Coastguard Worker /// Decodes a broadcast of a subvector to a larger vector type. 92*9880d681SAndroid Build Coastguard Worker void DecodeSubVectorBroadcast(MVT DstVT, MVT SrcVT, 93*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 94*9880d681SAndroid Build Coastguard Worker 95*9880d681SAndroid Build Coastguard Worker /// Decode a PSHUFB mask from a raw array of constants such as from 96*9880d681SAndroid Build Coastguard Worker /// BUILD_VECTOR. 97*9880d681SAndroid Build Coastguard Worker void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask, 98*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 99*9880d681SAndroid Build Coastguard Worker 100*9880d681SAndroid Build Coastguard Worker /// Decode a BLEND immediate mask into a shuffle mask. 101*9880d681SAndroid Build Coastguard Worker void DecodeBLENDMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 102*9880d681SAndroid Build Coastguard Worker 103*9880d681SAndroid Build Coastguard Worker void DecodeVPERM2X128Mask(MVT VT, unsigned Imm, 104*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 105*9880d681SAndroid Build Coastguard Worker 106*9880d681SAndroid Build Coastguard Worker /// Decode a shuffle packed values at 128-bit granularity 107*9880d681SAndroid Build Coastguard Worker /// immediate mask into a shuffle mask. 108*9880d681SAndroid Build Coastguard Worker void decodeVSHUF64x2FamilyMask(MVT VT, unsigned Imm, 109*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 110*9880d681SAndroid Build Coastguard Worker 111*9880d681SAndroid Build Coastguard Worker /// Decodes the shuffle masks for VPERMQ/VPERMPD. 112*9880d681SAndroid Build Coastguard Worker void DecodeVPERMMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 113*9880d681SAndroid Build Coastguard Worker 114*9880d681SAndroid Build Coastguard Worker /// Decode a VPPERM mask from a raw array of constants such as from 115*9880d681SAndroid Build Coastguard Worker /// BUILD_VECTOR. 116*9880d681SAndroid Build Coastguard Worker /// This can only basic masks (permutes + zeros), not any of the other 117*9880d681SAndroid Build Coastguard Worker /// operations that VPPERM can perform. 118*9880d681SAndroid Build Coastguard Worker void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask, 119*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 120*9880d681SAndroid Build Coastguard Worker 121*9880d681SAndroid Build Coastguard Worker /// Decode a zero extension instruction as a shuffle mask. 122*9880d681SAndroid Build Coastguard Worker void DecodeZeroExtendMask(MVT SrcScalarVT, MVT DstVT, 123*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 124*9880d681SAndroid Build Coastguard Worker 125*9880d681SAndroid Build Coastguard Worker /// Decode a move lower and zero upper instruction as a shuffle mask. 126*9880d681SAndroid Build Coastguard Worker void DecodeZeroMoveLowMask(MVT VT, SmallVectorImpl<int> &ShuffleMask); 127*9880d681SAndroid Build Coastguard Worker 128*9880d681SAndroid Build Coastguard Worker /// Decode a scalar float move instruction as a shuffle mask. 129*9880d681SAndroid Build Coastguard Worker void DecodeScalarMoveMask(MVT VT, bool IsLoad, 130*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 131*9880d681SAndroid Build Coastguard Worker 132*9880d681SAndroid Build Coastguard Worker /// Decode a SSE4A EXTRQ instruction as a v16i8 shuffle mask. 133*9880d681SAndroid Build Coastguard Worker void DecodeEXTRQIMask(int Len, int Idx, 134*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 135*9880d681SAndroid Build Coastguard Worker 136*9880d681SAndroid Build Coastguard Worker /// Decode a SSE4A INSERTQ instruction as a v16i8 shuffle mask. 137*9880d681SAndroid Build Coastguard Worker void DecodeINSERTQIMask(int Len, int Idx, 138*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 139*9880d681SAndroid Build Coastguard Worker 140*9880d681SAndroid Build Coastguard Worker /// Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants. 141*9880d681SAndroid Build Coastguard Worker void DecodeVPERMILPMask(MVT VT, ArrayRef<uint64_t> RawMask, 142*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 143*9880d681SAndroid Build Coastguard Worker 144*9880d681SAndroid Build Coastguard Worker /// Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants. 145*9880d681SAndroid Build Coastguard Worker void DecodeVPERMIL2PMask(MVT VT, unsigned M2Z, ArrayRef<uint64_t> RawMask, 146*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 147*9880d681SAndroid Build Coastguard Worker 148*9880d681SAndroid Build Coastguard Worker /// Decode a VPERM W/D/Q/PS/PD mask from a raw array of constants. 149*9880d681SAndroid Build Coastguard Worker void DecodeVPERMVMask(ArrayRef<uint64_t> RawMask, 150*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 151*9880d681SAndroid Build Coastguard Worker 152*9880d681SAndroid Build Coastguard Worker /// Decode a VPERMT2 W/D/Q/PS/PD mask from a raw array of constants. 153*9880d681SAndroid Build Coastguard Worker void DecodeVPERMV3Mask(ArrayRef<uint64_t> RawMask, 154*9880d681SAndroid Build Coastguard Worker SmallVectorImpl<int> &ShuffleMask); 155*9880d681SAndroid Build Coastguard Worker } // llvm namespace 156*9880d681SAndroid Build Coastguard Worker 157*9880d681SAndroid Build Coastguard Worker #endif 158