1 // RUN: tblgen %s | FileCheck %s
3 class ValueType<int size, int value> {
8 def v2i64 : ValueType<128, 22>; // 2 x i64 vector value
9 def v2f64 : ValueType<128, 28>; // 2 x f64 vector value
11 class Intrinsic<string name> {
15 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
16 dag PatternToMatch = patternToMatch;
17 list<dag> ResultInstrs = resultInstrs;
20 // Pat - A simple (but common) form of a pattern, which produces a simple result
21 // not needing a full list.
22 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
24 class Inst<bits<8> opcode, dag oopnds, dag iopnds, string asmstr,
26 bits<8> Opcode = opcode;
27 dag OutOperands = oopnds;
28 dag InOperands = iopnds;
29 string AssemblyString = asmstr;
30 list<dag> Pattern = pattern;
40 class Register<string n> {
44 class RegisterClass<list<ValueType> regTypes, list<Register> regList> {
45 list<ValueType> RegTypes = regTypes;
46 list<Register> MemberList = regList;
49 def XMM0: Register<"xmm0">;
50 def XMM1: Register<"xmm1">;
51 def XMM2: Register<"xmm2">;
52 def XMM3: Register<"xmm3">;
53 def XMM4: Register<"xmm4">;
54 def XMM5: Register<"xmm5">;
55 def XMM6: Register<"xmm6">;
56 def XMM7: Register<"xmm7">;
57 def XMM8: Register<"xmm8">;
58 def XMM9: Register<"xmm9">;
59 def XMM10: Register<"xmm10">;
60 def XMM11: Register<"xmm11">;
61 def XMM12: Register<"xmm12">;
62 def XMM13: Register<"xmm13">;
63 def XMM14: Register<"xmm14">;
64 def XMM15: Register<"xmm15">;
66 def VR128 : RegisterClass<[v2i64, v2f64],
67 [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
68 XMM8, XMM9, XMM10, XMM11,
69 XMM12, XMM13, XMM14, XMM15]>;
72 def REGCLASS : RegisterClass<[], []>;
84 def int_x86_sse2_add_ps : Intrinsic<"addps">;
85 def int_x86_sse2_add_pd : Intrinsic<"addpd">;
86 def INTRINSIC : Intrinsic<"Dummy">;
90 class MakePatImpl<list<dag> patterns> : Pat<patterns[0], patterns[1]>;
91 class MakePat<list<dag> patterns,
93 string intr> : MakePatImpl<!foreach(Decls.pattern, patterns,
94 !foreach(Decls.operand, Decls.pattern,
95 !subst(INTRINSIC, !cast<Intrinsic>(!subst("SUFFIX", suffix, intr)),
96 !subst(REGCLASS, VR128,
97 !subst(MNEMONIC, set, Decls.operand)))))>;
99 class Base<bits<8> opcode, dag opnds, dag iopnds, string asmstr, Intrinsic intr,
100 list<list<dag>> patterns>
101 : Inst<opcode, opnds, iopnds, asmstr,
102 !foreach(Decls.pattern, patterns[0],
103 !foreach(Decls.operand, Decls.pattern,
104 !subst(INTRINSIC, intr,
105 !subst(REGCLASS, VR128,
106 !subst(MNEMONIC, set, Decls.operand)))))>;
108 multiclass arith<bits<8> opcode, string asmstr, string intr, list<list<dag>> patterns> {
109 def PS : Base<opcode, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
110 !strconcat(asmstr, "\t$dst, $src1, $src2"), !cast<Intrinsic>(!subst("SUFFIX", "_ps", intr)), patterns>;
112 def PD : Base<opcode, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
113 !strconcat(asmstr, "\t$dst, $src1, $src2"), !cast<Intrinsic>(!subst("SUFFIX", "_pd", intr)), patterns>;
115 multidef <patterns, list<dag> pats, 1> : MakePat<pats, "_ps", intr>;
116 multidef <patterns, list<dag> pats, 1> : MakePat<pats, "_pd", intr>;
119 defm ADD : arith<0x58, "add", "int_x86_sse2_addSUFFIX",
121 [[(set REGCLASS:$dst, (INTRINSIC REGCLASS:$src1, REGCLASS:$src2))],
122 [(set REGCLASS:$dst, (bitconvert (INTRINSIC REGCLASS:$src1, REGCLASS:$src2))),
123 (MNEMONIC REGCLASS:$dst, REGCLASS:$src)],
124 [(set REGCLASS:$dst, (add (INTRINSIC REGCLASS:$src1, REGCLASS:$src2))),
125 (MNEMONIC (add REGCLASS:$dst, REGCLASS:$src))]]>;
127 // CHECK: [(set VR128:$dst, (int_x86_sse2_add_pd VR128:$src1, VR128:$src2))]
128 // CHECK: [(set VR128:$dst, (int_x86_sse2_add_ps VR128:$src1, VR128:$src2))]