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