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