X86ShuffleDecode.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #ifndef LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
  14. #define LLVM_LIB_TARGET_X86_UTILS_X86SHUFFLEDECODE_H
  15. #include <cstdint>
  16. //===----------------------------------------------------------------------===//
  17. // Vector Mask Decoding
  18. //===----------------------------------------------------------------------===//
  19. namespace llvm {
  20. class APInt;
  21. template <typename T> class ArrayRef;
  22. template <typename T> class SmallVectorImpl;
  23. enum { SM_SentinelUndef = -1, SM_SentinelZero = -2 };
  24. /// Decode a 128-bit INSERTPS instruction as a v4f32 shuffle mask.
  25. void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
  26. // Insert the bottom Len elements from a second source into a vector starting at
  27. // element Idx.
  28. void DecodeInsertElementMask(unsigned NumElts, unsigned Idx, unsigned Len,
  29. SmallVectorImpl<int> &ShuffleMask);
  30. /// Decode a MOVHLPS instruction as a v2f64/v4f32 shuffle mask.
  31. /// i.e. <3,1> or <6,7,2,3>
  32. void DecodeMOVHLPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);
  33. /// Decode a MOVLHPS instruction as a v2f64/v4f32 shuffle mask.
  34. /// i.e. <0,2> or <0,1,4,5>
  35. void DecodeMOVLHPSMask(unsigned NElts, SmallVectorImpl<int> &ShuffleMask);
  36. void DecodeMOVSLDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
  37. void DecodeMOVSHDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
  38. void DecodeMOVDDUPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
  39. void DecodePSLLDQMask(unsigned NumElts, unsigned Imm,
  40. SmallVectorImpl<int> &ShuffleMask);
  41. void DecodePSRLDQMask(unsigned NumElts, unsigned Imm,
  42. SmallVectorImpl<int> &ShuffleMask);
  43. void DecodePALIGNRMask(unsigned NumElts, unsigned Imm,
  44. SmallVectorImpl<int> &ShuffleMask);
  45. void DecodeVALIGNMask(unsigned NumElts, unsigned Imm,
  46. SmallVectorImpl<int> &ShuffleMask);
  47. /// Decodes the shuffle masks for pshufd/pshufw/vpermilpd/vpermilps.
  48. void DecodePSHUFMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
  49. SmallVectorImpl<int> &ShuffleMask);
  50. /// Decodes the shuffle masks for pshufhw.
  51. void DecodePSHUFHWMask(unsigned NumElts, unsigned Imm,
  52. SmallVectorImpl<int> &ShuffleMask);
  53. /// Decodes the shuffle masks for pshuflw.
  54. void DecodePSHUFLWMask(unsigned NumElts, unsigned Imm,
  55. SmallVectorImpl<int> &ShuffleMask);
  56. /// Decodes a PSWAPD 3DNow! instruction.
  57. void DecodePSWAPMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
  58. /// Decodes the shuffle masks for shufp*.
  59. void DecodeSHUFPMask(unsigned NumElts, unsigned ScalarBits, unsigned Imm,
  60. SmallVectorImpl<int> &ShuffleMask);
  61. /// Decodes the shuffle masks for unpckhps/unpckhpd and punpckh*.
  62. void DecodeUNPCKHMask(unsigned NumElts, unsigned ScalarBits,
  63. SmallVectorImpl<int> &ShuffleMask);
  64. /// Decodes the shuffle masks for unpcklps/unpcklpd and punpckl*.
  65. void DecodeUNPCKLMask(unsigned NumElts, unsigned ScalarBits,
  66. SmallVectorImpl<int> &ShuffleMask);
  67. /// Decodes a broadcast of the first element of a vector.
  68. void DecodeVectorBroadcast(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
  69. /// Decodes a broadcast of a subvector to a larger vector type.
  70. void DecodeSubVectorBroadcast(unsigned DstNumElts, unsigned SrcNumElts,
  71. SmallVectorImpl<int> &ShuffleMask);
  72. /// Decode a PSHUFB mask from a raw array of constants such as from
  73. /// BUILD_VECTOR.
  74. void DecodePSHUFBMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
  75. SmallVectorImpl<int> &ShuffleMask);
  76. /// Decode a BLEND immediate mask into a shuffle mask.
  77. void DecodeBLENDMask(unsigned NumElts, unsigned Imm,
  78. SmallVectorImpl<int> &ShuffleMask);
  79. void DecodeVPERM2X128Mask(unsigned NumElts, unsigned Imm,
  80. SmallVectorImpl<int> &ShuffleMask);
  81. /// Decode a shuffle packed values at 128-bit granularity
  82. /// (SHUFF32x4/SHUFF64x2/SHUFI32x4/SHUFI64x2)
  83. /// immediate mask into a shuffle mask.
  84. void decodeVSHUF64x2FamilyMask(unsigned NumElts, unsigned ScalarSize,
  85. unsigned Imm, SmallVectorImpl<int> &ShuffleMask);
  86. /// Decodes the shuffle masks for VPERMQ/VPERMPD.
  87. void DecodeVPERMMask(unsigned NumElts, unsigned Imm,
  88. SmallVectorImpl<int> &ShuffleMask);
  89. /// Decode a VPPERM mask from a raw array of constants such as from
  90. /// BUILD_VECTOR.
  91. /// This can only basic masks (permutes + zeros), not any of the other
  92. /// operations that VPPERM can perform.
  93. void DecodeVPPERMMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
  94. SmallVectorImpl<int> &ShuffleMask);
  95. /// Decode a zero extension instruction as a shuffle mask.
  96. void DecodeZeroExtendMask(unsigned SrcScalarBits, unsigned DstScalarBits,
  97. unsigned NumDstElts, bool IsAnyExtend,
  98. SmallVectorImpl<int> &ShuffleMask);
  99. /// Decode a move lower and zero upper instruction as a shuffle mask.
  100. void DecodeZeroMoveLowMask(unsigned NumElts, SmallVectorImpl<int> &ShuffleMask);
  101. /// Decode a scalar float move instruction as a shuffle mask.
  102. void DecodeScalarMoveMask(unsigned NumElts, bool IsLoad,
  103. SmallVectorImpl<int> &ShuffleMask);
  104. /// Decode a SSE4A EXTRQ instruction as a shuffle mask.
  105. void DecodeEXTRQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,
  106. SmallVectorImpl<int> &ShuffleMask);
  107. /// Decode a SSE4A INSERTQ instruction as a shuffle mask.
  108. void DecodeINSERTQIMask(unsigned NumElts, unsigned EltSize, int Len, int Idx,
  109. SmallVectorImpl<int> &ShuffleMask);
  110. /// Decode a VPERMILPD/VPERMILPS variable mask from a raw array of constants.
  111. void DecodeVPERMILPMask(unsigned NumElts, unsigned ScalarBits,
  112. ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
  113. SmallVectorImpl<int> &ShuffleMask);
  114. /// Decode a VPERMIL2PD/VPERMIL2PS variable mask from a raw array of constants.
  115. void DecodeVPERMIL2PMask(unsigned NumElts, unsigned ScalarBits, unsigned M2Z,
  116. ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
  117. SmallVectorImpl<int> &ShuffleMask);
  118. /// Decode a VPERM W/D/Q/PS/PD mask from a raw array of constants.
  119. void DecodeVPERMVMask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
  120. SmallVectorImpl<int> &ShuffleMask);
  121. /// Decode a VPERMT2 W/D/Q/PS/PD mask from a raw array of constants.
  122. void DecodeVPERMV3Mask(ArrayRef<uint64_t> RawMask, const APInt &UndefElts,
  123. SmallVectorImpl<int> &ShuffleMask);
  124. } // llvm namespace
  125. #endif