llvm.org GIT mirror llvm / 583b68f
[AVX] Recorganize X86ShuffleDecode into its own library (LLVMX86Utils.a) to break cyclic library dependencies between LLVMX86CodeGen.a and LLVMX86AsmParser.a. Previously this code was in a header file and marked static but AVX requires some additional functionality here that won't be used by all clients. Since including unused static functions causes a gcc compiler warning, keeping it as a header would break builds that use -Werror. Putting this in its own library solves both problems at once. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125765 91177308-0d34-0410-b5e6-96231b3b80d8 David Greene 9 years ago
8 changed file(s) with 241 addition(s) and 158 deletion(s). Raw diff Collapse all Expand all
1515 #include "X86GenInstrNames.inc"
1616 #include "llvm/MC/MCInst.h"
1717 #include "llvm/Support/raw_ostream.h"
18 #include "../X86ShuffleDecode.h"
18 #include "../Utils/X86ShuffleDecode.h"
1919 using namespace llvm;
2020
2121 //===----------------------------------------------------------------------===//
1919 X86GenCallingConv.inc X86GenSubtarget.inc \
2020 X86GenEDInfo.inc
2121
22 DIRS = InstPrinter AsmParser Disassembler TargetInfo
22 DIRS = InstPrinter AsmParser Disassembler TargetInfo Utils
2323
2424 include $(LEVEL)/Makefile.common
0 include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/.. )
1
2 add_llvm_library(LLVMX86Utils
3 X86ShuffleDecode.cpp
4 )
5 add_dependencies(LLVMX86Utils X86CodeGenTable_gen)
0 ##===- lib/Target/X86/Utils/Makefile -----------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8 LEVEL = ../../../..
9 LIBRARYNAME = LLVMX86Utils
10
11 # Hack: we need to include 'main' x86 target directory to grab private headers
12 CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
13
14 include $(LEVEL)/Makefile.common
0 //===-- X86ShuffleDecode.h - X86 shuffle decode logic ---------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Define several functions to decode x86 specific shuffle semantics into a
10 // generic vector mask.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "X86ShuffleDecode.h"
15
16 //===----------------------------------------------------------------------===//
17 // Vector Mask Decoding
18 //===----------------------------------------------------------------------===//
19
20 namespace llvm {
21
22 void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl &ShuffleMask) {
23 // Defaults the copying the dest value.
24 ShuffleMask.push_back(0);
25 ShuffleMask.push_back(1);
26 ShuffleMask.push_back(2);
27 ShuffleMask.push_back(3);
28
29 // Decode the immediate.
30 unsigned ZMask = Imm & 15;
31 unsigned CountD = (Imm >> 4) & 3;
32 unsigned CountS = (Imm >> 6) & 3;
33
34 // CountS selects which input element to use.
35 unsigned InVal = 4+CountS;
36 // CountD specifies which element of destination to update.
37 ShuffleMask[CountD] = InVal;
38 // ZMask zaps values, potentially overriding the CountD elt.
39 if (ZMask & 1) ShuffleMask[0] = SM_SentinelZero;
40 if (ZMask & 2) ShuffleMask[1] = SM_SentinelZero;
41 if (ZMask & 4) ShuffleMask[2] = SM_SentinelZero;
42 if (ZMask & 8) ShuffleMask[3] = SM_SentinelZero;
43 }
44
45 // <3,1> or <6,7,2,3>
46 void DecodeMOVHLPSMask(unsigned NElts,
47 SmallVectorImpl &ShuffleMask) {
48 for (unsigned i = NElts/2; i != NElts; ++i)
49 ShuffleMask.push_back(NElts+i);
50
51 for (unsigned i = NElts/2; i != NElts; ++i)
52 ShuffleMask.push_back(i);
53 }
54
55 // <0,2> or <0,1,4,5>
56 void DecodeMOVLHPSMask(unsigned NElts,
57 SmallVectorImpl &ShuffleMask) {
58 for (unsigned i = 0; i != NElts/2; ++i)
59 ShuffleMask.push_back(i);
60
61 for (unsigned i = 0; i != NElts/2; ++i)
62 ShuffleMask.push_back(NElts+i);
63 }
64
65 void DecodePSHUFMask(unsigned NElts, unsigned Imm,
66 SmallVectorImpl &ShuffleMask) {
67 for (unsigned i = 0; i != NElts; ++i) {
68 ShuffleMask.push_back(Imm % NElts);
69 Imm /= NElts;
70 }
71 }
72
73 void DecodePSHUFHWMask(unsigned Imm,
74 SmallVectorImpl &ShuffleMask) {
75 ShuffleMask.push_back(0);
76 ShuffleMask.push_back(1);
77 ShuffleMask.push_back(2);
78 ShuffleMask.push_back(3);
79 for (unsigned i = 0; i != 4; ++i) {
80 ShuffleMask.push_back(4+(Imm & 3));
81 Imm >>= 2;
82 }
83 }
84
85 void DecodePSHUFLWMask(unsigned Imm,
86 SmallVectorImpl &ShuffleMask) {
87 for (unsigned i = 0; i != 4; ++i) {
88 ShuffleMask.push_back((Imm & 3));
89 Imm >>= 2;
90 }
91 ShuffleMask.push_back(4);
92 ShuffleMask.push_back(5);
93 ShuffleMask.push_back(6);
94 ShuffleMask.push_back(7);
95 }
96
97 void DecodePUNPCKLMask(unsigned NElts,
98 SmallVectorImpl &ShuffleMask) {
99 for (unsigned i = 0; i != NElts/2; ++i) {
100 ShuffleMask.push_back(i);
101 ShuffleMask.push_back(i+NElts);
102 }
103 }
104
105 void DecodePUNPCKHMask(unsigned NElts,
106 SmallVectorImpl &ShuffleMask) {
107 for (unsigned i = 0; i != NElts/2; ++i) {
108 ShuffleMask.push_back(i+NElts/2);
109 ShuffleMask.push_back(i+NElts+NElts/2);
110 }
111 }
112
113 void DecodeSHUFPSMask(unsigned NElts, unsigned Imm,
114 SmallVectorImpl &ShuffleMask) {
115 // Part that reads from dest.
116 for (unsigned i = 0; i != NElts/2; ++i) {
117 ShuffleMask.push_back(Imm % NElts);
118 Imm /= NElts;
119 }
120 // Part that reads from src.
121 for (unsigned i = 0; i != NElts/2; ++i) {
122 ShuffleMask.push_back(Imm % NElts + NElts);
123 Imm /= NElts;
124 }
125 }
126
127 void DecodeUNPCKHPMask(unsigned NElts,
128 SmallVectorImpl &ShuffleMask) {
129 for (unsigned i = 0; i != NElts/2; ++i) {
130 ShuffleMask.push_back(i+NElts/2); // Reads from dest
131 ShuffleMask.push_back(i+NElts+NElts/2); // Reads from src
132 }
133 }
134
135
136 /// DecodeUNPCKLPMask - This decodes the shuffle masks for unpcklps/unpcklpd
137 /// etc. NElts indicates the number of elements in the vector allowing it to
138 /// handle different datatypes and vector widths.
139 void DecodeUNPCKLPMask(unsigned NElts,
140 SmallVectorImpl &ShuffleMask) {
141 for (unsigned i = 0; i != NElts/2; ++i) {
142 ShuffleMask.push_back(i); // Reads from dest
143 ShuffleMask.push_back(i+NElts); // Reads from src
144 }
145 }
146
147 } // llvm namespace
0 //===-- X86ShuffleDecode.h - X86 shuffle decode logic -----------*-C++-*---===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Define several functions to decode x86 specific shuffle semantics into a
10 // generic vector mask.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef X86_SHUFFLE_DECODE_H
15 #define X86_SHUFFLE_DECODE_H
16
17 #include "llvm/ADT/SmallVector.h"
18
19 //===----------------------------------------------------------------------===//
20 // Vector Mask Decoding
21 //===----------------------------------------------------------------------===//
22
23 namespace llvm {
24 enum {
25 SM_SentinelZero = ~0U
26 };
27
28 void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl &ShuffleMask);
29
30 // <3,1> or <6,7,2,3>
31 void DecodeMOVHLPSMask(unsigned NElts,
32 SmallVectorImpl &ShuffleMask);
33
34 // <0,2> or <0,1,4,5>
35 void DecodeMOVLHPSMask(unsigned NElts,
36 SmallVectorImpl &ShuffleMask);
37
38 void DecodePSHUFMask(unsigned NElts, unsigned Imm,
39 SmallVectorImpl &ShuffleMask);
40
41 void DecodePSHUFHWMask(unsigned Imm,
42 SmallVectorImpl &ShuffleMask);
43
44 void DecodePSHUFLWMask(unsigned Imm,
45 SmallVectorImpl &ShuffleMask);
46
47 void DecodePUNPCKLMask(unsigned NElts,
48 SmallVectorImpl &ShuffleMask);
49
50 void DecodePUNPCKHMask(unsigned NElts,
51 SmallVectorImpl &ShuffleMask);
52
53 void DecodeSHUFPSMask(unsigned NElts, unsigned Imm,
54 SmallVectorImpl &ShuffleMask);
55
56 void DecodeUNPCKHPMask(unsigned NElts,
57 SmallVectorImpl &ShuffleMask);
58
59
60 /// DecodeUNPCKLPMask - This decodes the shuffle masks for unpcklps/unpcklpd
61 /// etc. NElts indicates the number of elements in the vector allowing it to
62 /// handle different datatypes and vector widths.
63 void DecodeUNPCKLPMask(unsigned NElts,
64 SmallVectorImpl &ShuffleMask);
65
66 } // llvm namespace
67
68 #endif
1515 #include "X86.h"
1616 #include "X86InstrBuilder.h"
1717 #include "X86ISelLowering.h"
18 #include "X86ShuffleDecode.h"
1918 #include "X86TargetMachine.h"
2019 #include "X86TargetObjectFile.h"
20 #include "Utils/X86ShuffleDecode.h"
2121 #include "llvm/CallingConv.h"
2222 #include "llvm/Constants.h"
2323 #include "llvm/DerivedTypes.h"
+0
-155
lib/Target/X86/X86ShuffleDecode.h less more
None //===-- X86ShuffleDecode.h - X86 shuffle decode logic ---------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Define several functions to decode x86 specific shuffle semantics into a
10 // generic vector mask.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef X86_SHUFFLE_DECODE_H
15 #define X86_SHUFFLE_DECODE_H
16
17 #include "llvm/ADT/SmallVector.h"
18 using namespace llvm;
19
20 //===----------------------------------------------------------------------===//
21 // Vector Mask Decoding
22 //===----------------------------------------------------------------------===//
23
24 enum {
25 SM_SentinelZero = ~0U
26 };
27
28 static inline
29 void DecodeINSERTPSMask(unsigned Imm, SmallVectorImpl &ShuffleMask) {
30 // Defaults the copying the dest value.
31 ShuffleMask.push_back(0);
32 ShuffleMask.push_back(1);
33 ShuffleMask.push_back(2);
34 ShuffleMask.push_back(3);
35
36 // Decode the immediate.
37 unsigned ZMask = Imm & 15;
38 unsigned CountD = (Imm >> 4) & 3;
39 unsigned CountS = (Imm >> 6) & 3;
40
41 // CountS selects which input element to use.
42 unsigned InVal = 4+CountS;
43 // CountD specifies which element of destination to update.
44 ShuffleMask[CountD] = InVal;
45 // ZMask zaps values, potentially overriding the CountD elt.
46 if (ZMask & 1) ShuffleMask[0] = SM_SentinelZero;
47 if (ZMask & 2) ShuffleMask[1] = SM_SentinelZero;
48 if (ZMask & 4) ShuffleMask[2] = SM_SentinelZero;
49 if (ZMask & 8) ShuffleMask[3] = SM_SentinelZero;
50 }
51
52 // <3,1> or <6,7,2,3>
53 static void DecodeMOVHLPSMask(unsigned NElts,
54 SmallVectorImpl &ShuffleMask) {
55 for (unsigned i = NElts/2; i != NElts; ++i)
56 ShuffleMask.push_back(NElts+i);
57
58 for (unsigned i = NElts/2; i != NElts; ++i)
59 ShuffleMask.push_back(i);
60 }
61
62 // <0,2> or <0,1,4,5>
63 static void DecodeMOVLHPSMask(unsigned NElts,
64 SmallVectorImpl &ShuffleMask) {
65 for (unsigned i = 0; i != NElts/2; ++i)
66 ShuffleMask.push_back(i);
67
68 for (unsigned i = 0; i != NElts/2; ++i)
69 ShuffleMask.push_back(NElts+i);
70 }
71
72 static void DecodePSHUFMask(unsigned NElts, unsigned Imm,
73 SmallVectorImpl &ShuffleMask) {
74 for (unsigned i = 0; i != NElts; ++i) {
75 ShuffleMask.push_back(Imm % NElts);
76 Imm /= NElts;
77 }
78 }
79
80 static void DecodePSHUFHWMask(unsigned Imm,
81 SmallVectorImpl &ShuffleMask) {
82 ShuffleMask.push_back(0);
83 ShuffleMask.push_back(1);
84 ShuffleMask.push_back(2);
85 ShuffleMask.push_back(3);
86 for (unsigned i = 0; i != 4; ++i) {
87 ShuffleMask.push_back(4+(Imm & 3));
88 Imm >>= 2;
89 }
90 }
91
92 static void DecodePSHUFLWMask(unsigned Imm,
93 SmallVectorImpl &ShuffleMask) {
94 for (unsigned i = 0; i != 4; ++i) {
95 ShuffleMask.push_back((Imm & 3));
96 Imm >>= 2;
97 }
98 ShuffleMask.push_back(4);
99 ShuffleMask.push_back(5);
100 ShuffleMask.push_back(6);
101 ShuffleMask.push_back(7);
102 }
103
104 static void DecodePUNPCKLMask(unsigned NElts,
105 SmallVectorImpl &ShuffleMask) {
106 for (unsigned i = 0; i != NElts/2; ++i) {
107 ShuffleMask.push_back(i);
108 ShuffleMask.push_back(i+NElts);
109 }
110 }
111
112 static void DecodePUNPCKHMask(unsigned NElts,
113 SmallVectorImpl &ShuffleMask) {
114 for (unsigned i = 0; i != NElts/2; ++i) {
115 ShuffleMask.push_back(i+NElts/2);
116 ShuffleMask.push_back(i+NElts+NElts/2);
117 }
118 }
119
120 static void DecodeSHUFPSMask(unsigned NElts, unsigned Imm,
121 SmallVectorImpl &ShuffleMask) {
122 // Part that reads from dest.
123 for (unsigned i = 0; i != NElts/2; ++i) {
124 ShuffleMask.push_back(Imm % NElts);
125 Imm /= NElts;
126 }
127 // Part that reads from src.
128 for (unsigned i = 0; i != NElts/2; ++i) {
129 ShuffleMask.push_back(Imm % NElts + NElts);
130 Imm /= NElts;
131 }
132 }
133
134 static void DecodeUNPCKHPMask(unsigned NElts,
135 SmallVectorImpl &ShuffleMask) {
136 for (unsigned i = 0; i != NElts/2; ++i) {
137 ShuffleMask.push_back(i+NElts/2); // Reads from dest
138 ShuffleMask.push_back(i+NElts+NElts/2); // Reads from src
139 }
140 }
141
142
143 /// DecodeUNPCKLPMask - This decodes the shuffle masks for unpcklps/unpcklpd
144 /// etc. NElts indicates the number of elements in the vector allowing it to
145 /// handle different datatypes and vector widths.
146 static void DecodeUNPCKLPMask(unsigned NElts,
147 SmallVectorImpl &ShuffleMask) {
148 for (unsigned i = 0; i != NElts/2; ++i) {
149 ShuffleMask.push_back(i); // Reads from dest
150 ShuffleMask.push_back(i+NElts); // Reads from src
151 }
152 }
153
154 #endif