blob: dc21c19752c35be87f3f2a988d29b3edacdcdbb6 [file] [log] [blame]
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +00001//===-- 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 Takumifb3bd712015-05-25 01:43:23 +000019
20//===----------------------------------------------------------------------===//
21// Vector Mask Decoding
22//===----------------------------------------------------------------------===//
23
24namespace llvm {
Mehdi Aminib550cb12016-04-18 09:17:29 +000025template <typename T> class ArrayRef;
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000026class MVT;
27
28enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 };
29
Simon Pilgrim47617032016-04-08 14:17:07 +000030/// Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000031void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
32
Simon Pilgrima3d67442016-02-07 15:39:22 +000033// Insert the bottom Len elements from a second source into a vector starting at
34// element Idx.
35void DecodeInsertElementMask(MVT VT, unsigned Idx, unsigned Len,
36 SmallVectorImpl<int> &ShuffleMask);
37
Simon Pilgrim47617032016-04-08 14:17:07 +000038/// Decode a MOVHLPS instruction as a v2f64/v4f32 shuffle mask.
39/// i.e. <3,1> or <6,7,2,3>
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000040void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);
41
Simon Pilgrim47617032016-04-08 14:17:07 +000042/// Decode a MOVLHPS instruction as a v2f64/v4f32 shuffle mask.
43/// i.e. <0,2> or <0,1,4,5>
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000044void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);
45
46void DecodeMOVSLDUPMask(MVT VT, SmallVectorImpl<int> &ShuffleMask);
47
48void DecodeMOVSHDUPMask(MVT VT, SmallVectorImpl<int> &ShuffleMask);
49
50void DecodeMOVDDUPMask(MVT VT, SmallVectorImpl<int> &ShuffleMask);
51
52void DecodePSLLDQMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
53
54void DecodePSRLDQMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
55
56void DecodePALIGNRMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
57
Simon Pilgrim47617032016-04-08 14:17:07 +000058/// Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps.
59/// VT indicates the type of the vector allowing it to handle different
60/// datatypes and vector widths.
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000061void DecodePSHUFMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
62
Simon Pilgrim47617032016-04-08 14:17:07 +000063/// Decodes the shuffle masks for pshufhw.
64/// VT indicates the type of the vector allowing it to handle different
65/// datatypes and vector widths.
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000066void DecodePSHUFHWMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
67
Simon Pilgrim47617032016-04-08 14:17:07 +000068/// Decodes the shuffle masks for pshuflw.
69/// VT indicates the type of the vector allowing it to handle different
70/// datatypes and vector widths.
71void DecodePSHUFLWMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000072
Simon Pilgrim47617032016-04-08 14:17:07 +000073/// Decodes a PSWAPD 3DNow! instruction.
Simon Pilgrimf8f86ab2015-09-13 11:28:45 +000074void DecodePSWAPMask(MVT VT, SmallVectorImpl<int> &ShuffleMask);
75
Simon Pilgrimfd4b9b02016-04-16 17:52:07 +000076/// Decodes the shuffle masks for shufp*.
Simon Pilgrim47617032016-04-08 14:17:07 +000077/// VT indicates the type of the vector allowing it to handle different
78/// datatypes and vector widths.
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000079void DecodeSHUFPMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
80
Simon Pilgrim47617032016-04-08 14:17:07 +000081/// Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.
82/// VT indicates the type of the vector allowing it to handle different
83/// datatypes and vector widths.
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000084void DecodeUNPCKHMask(MVT VT, SmallVectorImpl<int> &ShuffleMask);
85
Simon Pilgrim47617032016-04-08 14:17:07 +000086/// Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.
87/// VT indicates the type of the vector allowing it to handle different
88/// datatypes and vector widths.
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000089void DecodeUNPCKLMask(MVT VT, SmallVectorImpl<int> &ShuffleMask);
90
Simon Pilgrimc941f6b2016-07-18 17:32:59 +000091/// Decodes a broadcast of the first element of a vector.
92void DecodeVectorBroadcast(MVT DstVT, SmallVectorImpl<int> &ShuffleMask);
93
Simon Pilgrima76a8e52016-07-14 12:07:43 +000094/// Decodes a broadcast of a subvector to a larger vector type.
95void DecodeSubVectorBroadcast(MVT DstVT, MVT SrcVT,
96 SmallVectorImpl<int> &ShuffleMask);
97
Simon Pilgrim47617032016-04-08 14:17:07 +000098/// Decode a PSHUFB mask from a raw array of constants such as from
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +000099/// BUILD_VECTOR.
100void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask,
101 SmallVectorImpl<int> &ShuffleMask);
102
Simon Pilgrim47617032016-04-08 14:17:07 +0000103/// Decode a BLEND immediate mask into a shuffle mask.
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +0000104void DecodeBLENDMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
105
106void DecodeVPERM2X128Mask(MVT VT, unsigned Imm,
107 SmallVectorImpl<int> &ShuffleMask);
108
Simon Pilgrim47617032016-04-08 14:17:07 +0000109/// Decode a shuffle packed values at 128-bit granularity
Igor Bregerd7bae452015-10-15 13:29:07 +0000110/// immediate mask into a shuffle mask.
111void decodeVSHUF64x2FamilyMask(MVT VT, unsigned Imm,
112 SmallVectorImpl<int> &ShuffleMask);
113
Simon Pilgrim47617032016-04-08 14:17:07 +0000114/// Decodes the shuffle masks for VPERMQ/VPERMPD.
Simon Pilgrima0d73832016-07-03 18:27:37 +0000115void DecodeVPERMMask(MVT VT, unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +0000116
Simon Pilgrimfd4b9b02016-04-16 17:52:07 +0000117/// Decode a VPPERM mask from a raw array of constants such as from
118/// BUILD_VECTOR.
119/// This can only basic masks (permutes + zeros), not any of the other
120/// operations that VPPERM can perform.
121void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask,
122 SmallVectorImpl<int> &ShuffleMask);
123
Simon Pilgrim47617032016-04-08 14:17:07 +0000124/// Decode a zero extension instruction as a shuffle mask.
Simon Pilgrime1b6db92016-02-06 16:33:42 +0000125void DecodeZeroExtendMask(MVT SrcScalarVT, MVT DstVT,
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +0000126 SmallVectorImpl<int> &ShuffleMask);
127
Simon Pilgrim47617032016-04-08 14:17:07 +0000128/// Decode a move lower and zero upper instruction as a shuffle mask.
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +0000129void DecodeZeroMoveLowMask(MVT VT, SmallVectorImpl<int> &ShuffleMask);
130
Simon Pilgrim47617032016-04-08 14:17:07 +0000131/// Decode a scalar float move instruction as a shuffle mask.
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +0000132void DecodeScalarMoveMask(MVT VT, bool IsLoad,
133 SmallVectorImpl<int> &ShuffleMask);
Simon Pilgrimd85cae32015-07-06 20:46:41 +0000134
Simon Pilgrim47617032016-04-08 14:17:07 +0000135/// Decode a SSE4A EXTRQ instruction as a v16i8 shuffle mask.
Simon Pilgrimd85cae32015-07-06 20:46:41 +0000136void DecodeEXTRQIMask(int Len, int Idx,
137 SmallVectorImpl<int> &ShuffleMask);
138
Simon Pilgrim47617032016-04-08 14:17:07 +0000139/// Decode a SSE4A INSERTQ instruction as a v16i8 shuffle mask.
Simon Pilgrimd85cae32015-07-06 20:46:41 +0000140void DecodeINSERTQIMask(int Len, int Idx,
141 SmallVectorImpl<int> &ShuffleMask);
Elena Demikhovskye88038f2015-09-08 06:38:21 +0000142
Simon Pilgrim47617032016-04-08 14:17:07 +0000143/// Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants.
Simon Pilgrim40e1a712016-03-05 22:53:31 +0000144void DecodeVPERMILPMask(MVT VT, ArrayRef<uint64_t> RawMask,
145 SmallVectorImpl<int> &ShuffleMask);
146
Simon Pilgrim64c6de42016-06-05 15:21:30 +0000147/// Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants.
148void DecodeVPERMIL2PMask(MVT VT, unsigned M2Z, ArrayRef<uint64_t> RawMask,
149 SmallVectorImpl<int> &ShuffleMask);
150
Simon Pilgrim47617032016-04-08 14:17:07 +0000151/// Decode a VPERM W/D/Q/PS/PD mask from a raw array of constants.
Elena Demikhovskye88038f2015-09-08 06:38:21 +0000152void DecodeVPERMVMask(ArrayRef<uint64_t> RawMask,
153 SmallVectorImpl<int> &ShuffleMask);
154
Simon Pilgrim47617032016-04-08 14:17:07 +0000155/// Decode a VPERMT2 W/D/Q/PS/PD mask from a raw array of constants.
Elena Demikhovskye88038f2015-09-08 06:38:21 +0000156void DecodeVPERMV3Mask(ArrayRef<uint64_t> RawMask,
157 SmallVectorImpl<int> &ShuffleMask);
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000158} // llvm namespace
NAKAMURA Takumifb3bd712015-05-25 01:43:23 +0000159
160#endif