Home | History | Annotate | Line # | Download | only in MCTargetDesc
      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
    167