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 23namespace llvm { 24class APInt; 25template <typename T> class ArrayRef; 26template <typename T> class SmallVectorImpl; 27 28enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 }; 29 30/// Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask. 31void 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. 35void 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> 40void 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> 44void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask); 45 46void DecodeMOVSLDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask); 47 48void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask); 49 50void DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask); 51 52void DecodePSLLDQMask(unsigned NumElts, unsigned Imm, 53 SmallVectorImpl<int> &ShuffleMask); 54 55void DecodePSRLDQMask(unsigned NumElts, unsigned Imm, 56 SmallVectorImpl<int> &ShuffleMask); 57 58void DecodePALIGNRMask(unsigned NumElts, unsigned Imm, 59 SmallVectorImpl<int> &ShuffleMask); 60 61void DecodeVALIGNMask(unsigned NumElts, unsigned Imm, 62 SmallVectorImpl<int> &ShuffleMask); 63 64/// Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps. 65void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm, 66 SmallVectorImpl<int> &ShuffleMask); 67 68/// Decodes the shuffle masks for pshufhw. 69void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm, 70 SmallVectorImpl<int> &ShuffleMask); 71 72/// Decodes the shuffle masks for pshuflw. 73void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm, 74 SmallVectorImpl<int> &ShuffleMask); 75 76/// Decodes a PSWAPD 3DNow! instruction. 77void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask); 78 79/// Decodes the shuffle masks for shufp*. 80void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm, 81 SmallVectorImpl<int> &ShuffleMask); 82 83/// Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*. 84void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits, 85 SmallVectorImpl<int> &ShuffleMask); 86 87/// Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*. 88void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits, 89 SmallVectorImpl<int> &ShuffleMask); 90 91/// Decodes a broadcast of the first element of a vector. 92void DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask); 93 94/// Decodes a broadcast of a subvector to a larger vector type. 95void 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. 100void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts, 101 SmallVectorImpl<int> &ShuffleMask); 102 103/// Decode a BLEND immediate mask into a shuffle mask. 104void DecodeBLENDMask(unsigned NumElts, unsigned Imm, 105 SmallVectorImpl<int> &ShuffleMask); 106 107void 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. 113void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize, 114 unsigned Imm, SmallVectorImpl<int> &ShuffleMask); 115 116/// Decodes the shuffle masks for VPERMQ/VPERMPD. 117void 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. 124void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts, 125 SmallVectorImpl<int> &ShuffleMask); 126 127/// Decode a zero extension instruction as a shuffle mask. 128void 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. 133void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask); 134 135/// Decode a scalar float move instruction as a shuffle mask. 136void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad, 137 SmallVectorImpl<int> &ShuffleMask); 138 139/// Decode a SSE4A EXTRQ instruction as a shuffle mask. 140void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx, 141 SmallVectorImpl<int> &ShuffleMask); 142 143/// Decode a SSE4A INSERTQ instruction as a shuffle mask. 144void 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. 148void 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. 153void 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. 158void 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. 162void DecodeVPERMV3Mask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts, 163 SmallVectorImpl<int> &ShuffleMask); 164} // llvm namespace 165 166#endif 167