Path: blob/main/contrib/llvm-project/llvm/lib/Target/X86/MCTargetDesc/X86ShuffleDecode.h
35294 views
//===-- X86ShuffleDecode.h - X86 shuffle decode logic -----------*-C++-*---===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Define several functions to decode x86 specific shuffle semantics into a9// generic vector mask.10//11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H14#define LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H1516#include <cstdint>1718//===----------------------------------------------------------------------===//19// Vector Mask Decoding20//===----------------------------------------------------------------------===//2122namespace llvm {23class APInt;24template <typename T> class ArrayRef;25template <typename T> class SmallVectorImpl;2627enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 };2829/// Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.30void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask);3132// Insert the bottom Len elements from a second source into a vector starting at33// element Idx.34void DecodeInsertElementMask(unsigned NumElts, unsigned Idx, unsigned Len,35SmallVectorImpl<int> &ShuffleMask);3637/// Decode a MOVHLPS instruction as a v2f64/v4f32 shuffle mask.38/// i.e. <3,1> or <6,7,2,3>39void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);4041/// Decode a MOVLHPS instruction as a v2f64/v4f32 shuffle mask.42/// i.e. <0,2> or <0,1,4,5>43void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);4445void DecodeMOVSLDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);4647void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);4849void DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);5051void DecodePSLLDQMask(unsigned NumElts, unsigned Imm,52SmallVectorImpl<int> &ShuffleMask);5354void DecodePSRLDQMask(unsigned NumElts, unsigned Imm,55SmallVectorImpl<int> &ShuffleMask);5657void DecodePALIGNRMask(unsigned NumElts, unsigned Imm,58SmallVectorImpl<int> &ShuffleMask);5960void DecodeVALIGNMask(unsigned NumElts, unsigned Imm,61SmallVectorImpl<int> &ShuffleMask);6263/// Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps.64void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,65SmallVectorImpl<int> &ShuffleMask);6667/// Decodes the shuffle masks for pshufhw.68void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm,69SmallVectorImpl<int> &ShuffleMask);7071/// Decodes the shuffle masks for pshuflw.72void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm,73SmallVectorImpl<int> &ShuffleMask);7475/// Decodes a PSWAPD 3DNow! instruction.76void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);7778/// Decodes the shuffle masks for shufp*.79void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,80SmallVectorImpl<int> &ShuffleMask);8182/// Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.83void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits,84SmallVectorImpl<int> &ShuffleMask);8586/// Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.87void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits,88SmallVectorImpl<int> &ShuffleMask);8990/// Decodes a broadcast of the first element of a vector.91void DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);9293/// Decodes a broadcast of a subvector to a larger vector type.94void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts,95SmallVectorImpl<int> &ShuffleMask);9697/// Decode a PSHUFB mask from a raw array of constants such as from98/// BUILD_VECTOR.99void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,100SmallVectorImpl<int> &ShuffleMask);101102/// Decode a BLEND immediate mask into a shuffle mask.103void DecodeBLENDMask(unsigned NumElts, unsigned Imm,104SmallVectorImpl<int> &ShuffleMask);105106void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm,107SmallVectorImpl<int> &ShuffleMask);108109/// Decode a shuffle packed values at 128-bit granularity110/// (SHUFF32x4/SHUFF64x2/SHUFI32x4/SHUFI64x2)111/// immediate mask into a shuffle mask.112void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize,113unsigned Imm, SmallVectorImpl<int> &ShuffleMask);114115/// Decodes the shuffle masks for VPERMQ/VPERMPD.116void DecodeVPERMMask(unsigned NumElts, unsigned Imm,117SmallVectorImpl<int> &ShuffleMask);118119/// Decode a VPPERM mask from a raw array of constants such as from120/// BUILD_VECTOR.121/// This can only basic masks (permutes + zeros), not any of the other122/// operations that VPPERM can perform.123void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,124SmallVectorImpl<int> &ShuffleMask);125126/// Decode a zero extension instruction as a shuffle mask.127void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits,128unsigned NumDstElts, bool IsAnyExtend,129SmallVectorImpl<int> &ShuffleMask);130131/// Decode a move lower and zero upper instruction as a shuffle mask.132void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);133134/// Decode a scalar float move instruction as a shuffle mask.135void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad,136SmallVectorImpl<int> &ShuffleMask);137138/// Decode a SSE4A EXTRQ instruction as a shuffle mask.139void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,140SmallVectorImpl<int> &ShuffleMask);141142/// Decode a SSE4A INSERTQ instruction as a shuffle mask.143void DecodeINSERTQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,144SmallVectorImpl<int> &ShuffleMask);145146/// Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants.147void DecodeVPERMILPMask(unsigned NumElts, unsigned ScalarBits,148ArrayRef<uint64_t> RawMask, const APInt &UndefElts,149SmallVectorImpl<int> &ShuffleMask);150151/// Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants.152void DecodeVPERMIL2PMask(unsigned NumElts, unsigned ScalarBits, unsigned M2Z,153ArrayRef<uint64_t> RawMask, const APInt &UndefElts,154SmallVectorImpl<int> &ShuffleMask);155156/// Decode a VPERM W/D/Q/PS/PD mask from a raw array of constants.157void DecodeVPERMVMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,158SmallVectorImpl<int> &ShuffleMask);159160/// Decode a VPERMT2 W/D/Q/PS/PD mask from a raw array of constants.161void DecodeVPERMV3Mask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,162SmallVectorImpl<int> &ShuffleMask);163} // llvm namespace164165#endif166167168