95b7ec2d42bdb2f216c9289ae1fdcecd378b1d63
[oota-llvm.git] / lib / Target / Alpha / AlphaInstrInfo.td
1 //===- AlphaInstrInfo.td - The Alpha Instruction Set -------*- tablegen -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 //
11 //===----------------------------------------------------------------------===//
12
13 include "AlphaInstrFormats.td"
14
15 //********************
16 //Paterns for matching
17 //********************
18
19 def immUExt8  : PatLeaf<(imm), [{
20   // immUExt8 predicate - True if the immediate fits in a 8-bit zero extended
21   // field.  Used by instructions like 'addi'.
22   return (unsigned long)N->getValue() == (unsigned char)N->getValue();
23 }]>;
24 def immSExt16  : PatLeaf<(imm), [{
25   // immSExt16 predicate - True if the immediate fits in a 16-bit sign extended
26   // field.  Used by instructions like 'lda'.
27   return (int)N->getValue() == (short)N->getValue();
28 }]>;
29
30 def iZAPX : SDNodeXForm<imm, [{
31   // Transformation function: get the imm to ZAPi
32   uint64_t UImm = (uint64_t)N->getValue();
33   unsigned int build = 0;
34   for(int i = 0; i < 8; ++i)
35   {
36     if ((UImm & 0x00FF) == 0x00FF)
37       build |= 1 << i;
38     else if ((UImm & 0x00FF) != 0)
39     { build = 0; break; }
40     UImm >>= 8;
41   }
42   return getI64Imm(build);
43 }]>;
44 def immZAP  : PatLeaf<(imm), [{
45   // immZAP predicate - True if the immediate fits is suitable for use in a
46   // ZAP instruction
47   uint64_t UImm = (uint64_t)N->getValue();
48   unsigned int build = 0;
49   for(int i = 0; i < 8; ++i)
50   {
51     if ((UImm & 0x00FF) == 0x00FF)
52       build |= 1 << i;
53     else if ((UImm & 0x00FF) != 0)
54     { build = 0; break; }
55     UImm >>= 8;
56   }
57   return build != 0;
58 }], iZAPX>;
59
60
61 def intop : PatFrag<(ops node:$op), (sext_inreg node:$op, i32)>;
62 def add4  : PatFrag<(ops node:$op1, node:$op2),
63                     (add (shl node:$op1, 2), node:$op2)>;
64 def sub4  : PatFrag<(ops node:$op1, node:$op2),
65                     (sub (shl node:$op1, 2), node:$op2)>;
66 def add8  : PatFrag<(ops node:$op1, node:$op2),
67                     (add (shl node:$op1, 3), node:$op2)>;
68 def sub8  : PatFrag<(ops node:$op1, node:$op2),
69                     (sub (shl node:$op1, 3), node:$op2)>;
70
71   // //#define FP    $15
72   // //#define RA    $26
73   // //#define PV    $27
74   // //#define GP    $29
75   // //#define SP    $30
76
77 def PHI : PseudoInstAlpha<(ops variable_ops), "#phi">;
78 def IDEF : PseudoInstAlpha<(ops GPRC:$RA), "#idef $RA">;
79 def WTF : PseudoInstAlpha<(ops variable_ops), "#wtf">;
80 def ADJUSTSTACKUP : PseudoInstAlpha<(ops variable_ops), "ADJUP">;
81 def ADJUSTSTACKDOWN : PseudoInstAlpha<(ops variable_ops), "ADJDOWN">;
82 def ALTENT : PseudoInstAlpha<(ops s64imm:$TARGET), "$TARGET:\n">;
83 def PCLABEL : PseudoInstAlpha<(ops s64imm:$num), "PCMARKER_$num:\n">;
84 def MEMLABEL : PseudoInstAlpha<(ops s64imm:$i, s64imm:$j, s64imm:$k, s64imm:$m),
85          "LSMARKER$$$i$$$j$$$k$$$m:\n">;
86
87 //*****************
88 //These are shortcuts, the assembler expands them
89 //*****************
90 //AT = R28
91 //T0-T7 = R1 - R8
92 //T8-T11 = R22-R25
93
94 //An even better improvement on the Int = SetCC(FP):  SelectCC!
95 //These are evil because they hide control flow in a MBB
96 //really the ISel should emit multiple MBB
97 let isTwoAddress = 1 in {
98 //Conditional move of an int based on a FP CC
99   def CMOVEQ_FP : PseudoInstAlpha<(ops GPRC:$RDEST, GPRC:$RSRC_F, GPRC:$RSRC_T, FPRC:$RCOND),
100                                   "fbne $RCOND, 42f\n\tbis $RSRC_T,$RSRC_T,$RDEST\n42:\n">;
101   def CMOVEQi_FP : PseudoInstAlpha<(ops GPRC:$RDEST, GPRC:$RSRC_F, u8imm:$L, FPRC:$RCOND),
102                                   "fbne $RCOND, 42f\n\taddq $$31,$L,$RDEST\n42:\n">;
103
104   def CMOVNE_FP : PseudoInstAlpha<(ops GPRC:$RDEST, GPRC:$RSRC_F, GPRC:$RSRC_T, FPRC:$RCOND),
105                                   "fbeq $RCOND, 42f\n\tbis $RSRC_T,$RSRC_T,$RDEST\n42:\n">;
106   def CMOVNEi_FP : PseudoInstAlpha<(ops GPRC:$RDEST, GPRC:$RSRC_F, u8imm:$L, FPRC:$RCOND),
107                                   "fbeq $RCOND, 42f\n\taddq $$31,$L,$RDEST\n42:\n">;
108 //Conditional move of an FP based on a Int CC
109   def FCMOVEQ_INT : PseudoInstAlpha<(ops GPRC:$RDEST, GPRC:$RSRC_F, GPRC:$RSRC_T, FPRC:$RCOND),
110                                   "bne $RCOND, 42f\n\tcpys $RSRC_T,$RSRC_T,$RDEST\n42:\n">;
111   def FCMOVNE_INT : PseudoInstAlpha<(ops GPRC:$RDEST, GPRC:$RSRC_F, GPRC:$RSRC_T, FPRC:$RCOND),
112                                   "beq $RCOND, 42f\n\tcpys $RSRC_T,$RSRC_T,$RDEST\n42:\n">;
113 }
114
115 //***********************
116 //Real instructions
117 //***********************
118
119 //Operation Form:
120
121 //conditional moves, int
122 def CMOVEQ   : OForm4<  0x11, 0x24, "cmoveq $RCOND,$RSRC,$RDEST">; //CMOVE if RCOND =  zero
123 def CMOVEQi  : OForm4L< 0x11, 0x24, "cmoveq $RCOND,$L,$RDEST">; //CMOVE if RCOND =  zero
124 def CMOVGE   : OForm4<  0x11, 0x46, "cmovge $RCOND,$RSRC,$RDEST">; //CMOVE if RCOND >= zero
125 def CMOVGEi  : OForm4L< 0x11, 0x46, "cmovge $RCOND,$L,$RDEST">; //CMOVE if RCOND >= zero
126 def CMOVGT   : OForm4<  0x11, 0x66, "cmovgt $RCOND,$RSRC,$RDEST">; //CMOVE if RCOND > zero
127 def CMOVGTi  : OForm4L< 0x11, 0x66, "cmovgt $RCOND,$L,$RDEST">; //CMOVE if RCOND > zero
128 def CMOVLBC  : OForm4<  0x11, 0x16, "cmovlbc $RCOND,$RSRC,$RDEST">; //CMOVE if RCOND low bit clear
129 def CMOVLBCi : OForm4L< 0x11, 0x16, "cmovlbc $RCOND,$L,$RDEST">; //CMOVE if RCOND low bit clear
130 def CMOVLBS  : OForm4<  0x11, 0x14, "cmovlbs $RCOND,$RSRC,$RDEST">; //CMOVE if RCOND low bit set
131 def CMOVLBSi : OForm4L< 0x11, 0x14, "cmovlbs $RCOND,$L,$RDEST">; //CMOVE if RCOND low bit set
132 def CMOVLE   : OForm4<  0x11, 0x64, "cmovle $RCOND,$RSRC,$RDEST">; //CMOVE if RCOND <= zero
133 def CMOVLEi  : OForm4L< 0x11, 0x64, "cmovle $RCOND,$L,$RDEST">; //CMOVE if RCOND <= zero
134 def CMOVLT   : OForm4<  0x11, 0x44, "cmovlt $RCOND,$RSRC,$RDEST">; //CMOVE if RCOND < zero
135 def CMOVLTi  : OForm4L< 0x11, 0x44, "cmovlt $RCOND,$L,$RDEST">; //CMOVE if RCOND < zero
136 def CMOVNE   : OForm4<  0x11, 0x26, "cmovne $RCOND,$RSRC,$RDEST">; //CMOVE if RCOND != zero
137 def CMOVNEi  : OForm4L< 0x11, 0x26, "cmovne $RCOND,$L,$RDEST">; //CMOVE if RCOND != zero
138
139 let isTwoAddress = 1 in {
140 //conditional moves, fp
141  def FCMOVEQ : FPFormCM<0x17, 0x02A, (ops FPRC:$RDEST, FPRC:$RSRC2, FPRC:$RSRC, FPRC:$RCOND),
142         "fcmoveq $RCOND,$RSRC,$RDEST">; //FCMOVE if = zero
143  def FCMOVGE : FPFormCM<0x17, 0x02D, (ops FPRC:$RDEST, FPRC:$RSRC2, FPRC:$RSRC, FPRC:$RCOND),
144         "fcmovge $RCOND,$RSRC,$RDEST">; //FCMOVE if >= zero
145  def FCMOVGT : FPFormCM<0x17, 0x02F, (ops FPRC:$RDEST, FPRC:$RSRC2, FPRC:$RSRC, FPRC:$RCOND),
146         "fcmovgt $RCOND,$RSRC,$RDEST">; //FCMOVE if > zero
147  def FCMOVLE : FPFormCM<0x17, 0x02E, (ops FPRC:$RDEST, FPRC:$RSRC2, FPRC:$RSRC, FPRC:$RCOND),
148         "fcmovle $RCOND,$RSRC,$RDEST">; //FCMOVE if <= zero
149  def FCMOVLT : FPFormCM<0x17, 0x02, (ops FPRC:$RDEST, FPRC:$RSRC2, FPRC:$RSRC, FPRC:$RCOND),
150         "fcmovlt $RCOND,$RSRC,$RDEST">; // FCMOVE if < zero
151  def FCMOVNE : FPFormCM<0x17, 0x02B, (ops FPRC:$RDEST, FPRC:$RSRC2, FPRC:$RSRC, FPRC:$RCOND),
152         "fcmovne $RCOND,$RSRC,$RDEST">; //FCMOVE if != zero
153 }
154
155 def ADDL     : OForm< 0x10, 0x00, "addl $RA,$RB,$RC",
156                       [(set GPRC:$RC, (intop (add GPRC:$RA, GPRC:$RB)))]>;
157 def ADDLi    : OFormL<0x10, 0x00, "addl $RA,$L,$RC",
158                       [(set GPRC:$RC, (intop (add GPRC:$RA, immUExt8:$L)))]>;
159 def ADDQ     : OForm< 0x10, 0x20, "addq $RA,$RB,$RC",
160                       [(set GPRC:$RC, (add GPRC:$RA, GPRC:$RB))]>;
161 def ADDQi    : OFormL<0x10, 0x20, "addq $RA,$L,$RC",
162                       [(set GPRC:$RC, (add GPRC:$RA, immUExt8:$L))]>;
163 //def AMASK    : OForm< 0x11, 0x61, "AMASK $RA,$RB,$RC", []>; //Architecture mask
164 //def AMASKi   : OFormL<0x11, 0x61, "AMASK $RA,$L,$RC", []>; //Architecture mask
165 def AND      : OForm< 0x11, 0x00, "and $RA,$RB,$RC",
166                       [(set GPRC:$RC, (and GPRC:$RA, GPRC:$RB))]>;
167 def ANDi     : OFormL<0x11, 0x00, "and $RA,$L,$RC",
168                       [(set GPRC:$RC, (and GPRC:$RA, immUExt8:$L))]>;
169 def BIC      : OForm< 0x11, 0x08, "bic $RA,$RB,$RC",
170                       [(set GPRC:$RC, (and GPRC:$RA, (not GPRC:$RB)))]>;
171 def BICi     : OFormL<0x11, 0x08, "bic $RA,$L,$RC", []>;
172 //                      [(set GPRC:$RC, (and GPRC:$RA, (not immUExt8:$L)))]>; //FIXME?
173 def BIS      : OForm< 0x11, 0x20, "bis $RA,$RB,$RC",
174                       [(set GPRC:$RC, (or GPRC:$RA, GPRC:$RB))]>;
175 def BISi     : OFormL<0x11, 0x20, "bis $RA,$L,$RC",
176                       [(set GPRC:$RC, (or GPRC:$RA, immUExt8:$L))]>;
177 def CTLZ     : OForm2<0x1C, 0x32, "CTLZ $RB,$RC", 
178                       [(set GPRC:$RC, (ctlz GPRC:$RB))]>;
179 def CTPOP    : OForm2<0x1C, 0x30, "CTPOP $RB,$RC", 
180                       [(set GPRC:$RC, (ctpop GPRC:$RB))]>;
181 def CTTZ     : OForm2<0x1C, 0x33, "CTTZ $RB,$RC", 
182                       [(set GPRC:$RC, (cttz GPRC:$RB))]>;
183 def EQV      : OForm< 0x11, 0x48, "eqv $RA,$RB,$RC",
184                       [(set GPRC:$RC, (xor GPRC:$RA, (not GPRC:$RB)))]>;
185 def EQVi     : OFormL<0x11, 0x48, "eqv $RA,$L,$RC", []>;
186 //                      [(set GPRC:$RC, (xor GPRC:$RA, (not immUExt8:$L)))]>;
187 //def EXTBL    : OForm< 0x12, 0x06, "EXTBL $RA,$RB,$RC", []>; //Extract byte low
188 //def EXTBLi   : OFormL<0x12, 0x06, "EXTBL $RA,$L,$RC", []>; //Extract byte low
189 //def EXTLH    : OForm< 0x12, 0x6A, "EXTLH $RA,$RB,$RC", []>; //Extract longword high
190 //def EXTLHi   : OFormL<0x12, 0x6A, "EXTLH $RA,$L,$RC", []>; //Extract longword high
191 //def EXTLL    : OForm< 0x12, 0x26, "EXTLL $RA,$RB,$RC", []>; //Extract longword low
192 //def EXTLLi   : OFormL<0x12, 0x26, "EXTLL $RA,$L,$RC", []>; //Extract longword low
193 //def EXTQH    : OForm< 0x12, 0x7A, "EXTQH $RA,$RB,$RC", []>; //Extract quadword high
194 //def EXTQHi   : OFormL<0x12, 0x7A, "EXTQH $RA,$L,$RC", []>; //Extract quadword high
195 //def EXTQ     : OForm< 0x12, 0x36, "EXTQ $RA,$RB,$RC", []>; //Extract quadword low
196 //def EXTQi    : OFormL<0x12, 0x36, "EXTQ $RA,$L,$RC", []>; //Extract quadword low
197 //def EXTWH    : OForm< 0x12, 0x5A, "EXTWH $RA,$RB,$RC", []>; //Extract word high
198 //def EXTWHi   : OFormL<0x12, 0x5A, "EXTWH $RA,$L,$RC", []>; //Extract word high
199 //def EXTWL    : OForm< 0x12, 0x16, "EXTWL $RA,$RB,$RC", []>; //Extract word low
200 //def EXTWLi   : OFormL<0x12, 0x16, "EXTWL $RA,$L,$RC", []>; //Extract word low
201 //def IMPLVER  : OForm< 0x11, 0x6C, "IMPLVER $RA,$RB,$RC", []>; //Implementation version
202 //def IMPLVERi : OFormL<0x11, 0x6C, "IMPLVER $RA,$L,$RC", []>; //Implementation version
203 //def INSBL    : OForm< 0x12, 0x0B, "INSBL $RA,$RB,$RC", []>; //Insert byte low
204 //def INSBLi   : OFormL<0x12, 0x0B, "INSBL $RA,$L,$RC", []>; //Insert byte low
205 //def INSLH    : OForm< 0x12, 0x67, "INSLH $RA,$RB,$RC", []>; //Insert longword high
206 //def INSLHi   : OFormL<0x12, 0x67, "INSLH $RA,$L,$RC", []>; //Insert longword high
207 //def INSLL    : OForm< 0x12, 0x2B, "INSLL $RA,$RB,$RC", []>; //Insert longword low
208 //def INSLLi   : OFormL<0x12, 0x2B, "INSLL $RA,$L,$RC", []>; //Insert longword low
209 //def INSQH    : OForm< 0x12, 0x77, "INSQH $RA,$RB,$RC", []>; //Insert quadword high
210 //def INSQHi   : OFormL<0x12, 0x77, "INSQH $RA,$L,$RC", []>; //Insert quadword high
211 //def INSQL    : OForm< 0x12, 0x3B, "INSQL $RA,$RB,$RC", []>; //Insert quadword low
212 //def INSQLi   : OFormL<0x12, 0x3B, "INSQL $RA,$L,$RC", []>; //Insert quadword low
213 //def INSWH    : OForm< 0x12, 0x57, "INSWH $RA,$RB,$RC", []>; //Insert word high
214 //def INSWHi   : OFormL<0x12, 0x57, "INSWH $RA,$L,$RC", []>; //Insert word high
215 //def INSWL    : OForm< 0x12, 0x1B, "INSWL $RA,$RB,$RC", []>; //Insert word low
216 //def INSWLi   : OFormL<0x12, 0x1B, "INSWL $RA,$L,$RC", []>; //Insert word low
217 //def MSKBL    : OForm< 0x12, 0x02, "MSKBL $RA,$RB,$RC", []>; //Mask byte low
218 //def MSKBLi   : OFormL<0x12, 0x02, "MSKBL $RA,$L,$RC", []>; //Mask byte low
219 //def MSKLH    : OForm< 0x12, 0x62, "MSKLH $RA,$RB,$RC", []>; //Mask longword high
220 //def MSKLHi   : OFormL<0x12, 0x62, "MSKLH $RA,$L,$RC", []>; //Mask longword high
221 //def MSKLL    : OForm< 0x12, 0x22, "MSKLL $RA,$RB,$RC", []>; //Mask longword low
222 //def MSKLLi   : OFormL<0x12, 0x22, "MSKLL $RA,$L,$RC", []>; //Mask longword low
223 //def MSKQH    : OForm< 0x12, 0x72, "MSKQH $RA,$RB,$RC", []>; //Mask quadword high
224 //def MSKQHi   : OFormL<0x12, 0x72, "MSKQH $RA,$L,$RC", []>; //Mask quadword high
225 //def MSKQL    : OForm< 0x12, 0x32, "MSKQL $RA,$RB,$RC", []>; //Mask quadword low
226 //def MSKQLi   : OFormL<0x12, 0x32, "MSKQL $RA,$L,$RC", []>; //Mask quadword low
227 //def MSKWH    : OForm< 0x12, 0x52, "MSKWH $RA,$RB,$RC", []>; //Mask word high
228 //def MSKWHi   : OFormL<0x12, 0x52, "MSKWH $RA,$L,$RC", []>; //Mask word high
229 //def MSKWL    : OForm< 0x12, 0x12, "MSKWL $RA,$RB,$RC", []>; //Mask word low
230 //def MSKWLi   : OFormL<0x12, 0x12, "MSKWL $RA,$L,$RC", []>; //Mask word low
231
232 def MULL     : OForm< 0x13, 0x00, "mull $RA,$RB,$RC",
233                       [(set GPRC:$RC, (intop (mul GPRC:$RA, GPRC:$RB)))]>;
234 def MULLi    : OFormL<0x13, 0x00, "mull $RA,$L,$RC",
235                       [(set GPRC:$RC, (intop (mul GPRC:$RA, immUExt8:$L)))]>;
236 def MULQ     : OForm< 0x13, 0x20, "mulq $RA,$RB,$RC",
237                       [(set GPRC:$RC, (mul GPRC:$RA, GPRC:$RB))]>;
238 def MULQi    : OFormL<0x13, 0x20, "mulq $RA,$L,$RC",
239                       [(set GPRC:$RC, (mul GPRC:$RA, immUExt8:$L))]>;
240 def ORNOT    : OForm< 0x11, 0x28, "ornot $RA,$RB,$RC",
241                       [(set GPRC:$RC, (or GPRC:$RA, (not GPRC:$RB)))]>;
242 def ORNOTi   : OFormL<0x11, 0x28, "ornot $RA,$L,$RC", []>;
243 //                      [(set GPRC:$RC, (or GPRC:$RA, (not immUExt8:$L)))]>;
244 def S4ADDL   : OForm< 0x10, 0x02, "s4addl $RA,$RB,$RC", 
245                       [(set GPRC:$RC, (intop (add4 GPRC:$RA, GPRC:$RB)))]>;
246 def S4ADDLi  : OFormL<0x10, 0x02, "s4addl $RA,$L,$RC", 
247                       [(set GPRC:$RC, (intop (add4 GPRC:$RA, immUExt8:$L)))]>;
248 def S4ADDQ   : OForm< 0x10, 0x22, "s4addq $RA,$RB,$RC", 
249                       [(set GPRC:$RC, (add4 GPRC:$RA, GPRC:$RB))]>;
250 def S4ADDQi  : OFormL<0x10, 0x22, "s4addq $RA,$L,$RC", 
251                       [(set GPRC:$RC, (add4 GPRC:$RA, immUExt8:$L))]>;
252 def S4SUBL   : OForm< 0x10, 0x0B, "s4subl $RA,$RB,$RC",
253                       [(set GPRC:$RC, (intop (sub4 GPRC:$RA, GPRC:$RB)))]>;
254 def S4SUBLi  : OFormL<0x10, 0x0B, "s4subl $RA,$L,$RC",
255                       [(set GPRC:$RC, (intop (sub4 GPRC:$RA, immUExt8:$L)))]>;
256 def S4SUBQ   : OForm< 0x10, 0x2B, "s4subq $RA,$RB,$RC", 
257                       [(set GPRC:$RC, (sub4 GPRC:$RA, GPRC:$RB))]>;
258 def S4SUBQi  : OFormL<0x10, 0x2B, "s4subq $RA,$L,$RC", 
259                       [(set GPRC:$RC, (sub4 GPRC:$RA, immUExt8:$L))]>;
260 def S8ADDL   : OForm< 0x10, 0x12, "s8addl $RA,$RB,$RC", 
261                       [(set GPRC:$RC, (intop (add8 GPRC:$RA, GPRC:$RB)))]>;
262 def S8ADDLi  : OFormL<0x10, 0x12, "s8addl $RA,$L,$RC", 
263                       [(set GPRC:$RC, (intop (add8 GPRC:$RA, immUExt8:$L)))]>;
264 def S8ADDQ   : OForm< 0x10, 0x32, "s8addq $RA,$RB,$RC", 
265                       [(set GPRC:$RC, (add8 GPRC:$RA, GPRC:$RB))]>;
266 def S8ADDQi  : OFormL<0x10, 0x32, "s8addq $RA,$L,$RC", 
267                       [(set GPRC:$RC, (add8 GPRC:$RA, immUExt8:$L))]>;
268 def S8SUBL   : OForm< 0x10, 0x1B, "s8subl $RA,$RB,$RC", 
269                       [(set GPRC:$RC, (intop (sub8 GPRC:$RA, GPRC:$RB)))]>;
270 def S8SUBLi  : OFormL<0x10, 0x1B, "s8subl $RA,$L,$RC", 
271                       [(set GPRC:$RC, (intop (sub8 GPRC:$RA, immUExt8:$L)))]>;
272 def S8SUBQ   : OForm< 0x10, 0x3B, "s8subq $RA,$RB,$RC", 
273                       [(set GPRC:$RC, (sub8 GPRC:$RA, GPRC:$RB))]>;
274 def S8SUBQi  : OFormL<0x10, 0x3B, "s8subq $RA,$L,$RC", 
275                       [(set GPRC:$RC, (sub8 GPRC:$RA, immUExt8:$L))]>;
276 def SEXTB    : OForm2<0x1C, 0x00, "sextb $RB,$RC", 
277                       [(set GPRC:$RC, (sext_inreg GPRC:$RB, i8))]>;
278 def SEXTW    : OForm2<0x1C, 0x01, "sextw $RB,$RC", 
279                       [(set GPRC:$RC, (sext_inreg GPRC:$RB, i16))]>;
280 def SL       : OForm< 0x12, 0x39, "sll $RA,$RB,$RC",
281                       [(set GPRC:$RC, (shl GPRC:$RA, GPRC:$RB))]>;
282 def SLi      : OFormL<0x12, 0x39, "sll $RA,$L,$RC",
283                       [(set GPRC:$RC, (shl GPRC:$RA, immUExt8:$L))]>;
284 def SRA      : OForm< 0x12, 0x3C, "sra $RA,$RB,$RC",
285                       [(set GPRC:$RC, (sra GPRC:$RA, GPRC:$RB))]>;
286 def SRAi     : OFormL<0x12, 0x3C, "sra $RA,$L,$RC",
287                       [(set GPRC:$RC, (sra GPRC:$RA, immUExt8:$L))]>;
288 def SRL      : OForm< 0x12, 0x34, "srl $RA,$RB,$RC",
289                       [(set GPRC:$RC, (srl GPRC:$RA, GPRC:$RB))]>;
290 def SRLi     : OFormL<0x12, 0x34, "srl $RA,$L,$RC",
291                       [(set GPRC:$RC, (srl GPRC:$RA, immUExt8:$L))]>;
292 def SUBL     : OForm< 0x10, 0x09, "subl $RA,$RB,$RC",
293                       [(set GPRC:$RC, (intop (sub GPRC:$RA, GPRC:$RB)))]>;
294 def SUBLi    : OFormL<0x10, 0x09, "subl $RA,$L,$RC",
295                       [(set GPRC:$RC, (intop (sub GPRC:$RA, immUExt8:$L)))]>;
296 def SUBQ     : OForm< 0x10, 0x29, "subq $RA,$RB,$RC",
297                       [(set GPRC:$RC, (sub GPRC:$RA, GPRC:$RB))]>;
298 def SUBQi    : OFormL<0x10, 0x29, "subq $RA,$L,$RC",
299                       [(set GPRC:$RC, (sub GPRC:$RA, immUExt8:$L))]>;
300 def UMULH    : OForm< 0x13, 0x30, "umulh $RA,$RB,$RC",
301                       [(set GPRC:$RC, (mulhu GPRC:$RA, GPRC:$RB))]>;                     
302 def UMULHi   : OFormL<0x13, 0x30, "umulh $RA,$L,$RC", 
303                       [(set GPRC:$RC, (mulhu GPRC:$RA, immUExt8:$L))]>;
304 def XOR      : OForm< 0x11, 0x40, "xor $RA,$RB,$RC",
305                       [(set GPRC:$RC, (xor GPRC:$RA, GPRC:$RB))]>;
306 def XORi     : OFormL<0x11, 0x40, "xor $RA,$L,$RC",
307                       [(set GPRC:$RC, (xor GPRC:$RA, immUExt8:$L))]>;
308 //FIXME: what to do about zap? the cases it catches are very complex
309 def ZAP      : OForm< 0x12, 0x30, "zap $RA,$RB,$RC", []>; //Zero bytes
310 //ZAPi is useless give ZAPNOTi
311 def ZAPi     : OFormL<0x12, 0x30, "zap $RA,$L,$RC", []>; //Zero bytes
312 //FIXME: what to do about zapnot? see ZAP :)
313 def ZAPNOT   : OForm< 0x12, 0x31, "zapnot $RA,$RB,$RC", []>; //Zero bytes not
314 def ZAPNOTi  : OFormL<0x12, 0x31, "zapnot $RA,$L,$RC", 
315                       [(set GPRC:$RC, (and GPRC:$RA, immZAP:$L))]>; 
316
317 //Comparison, int
318 def CMPBGE   : OForm< 0x10, 0x0F, "cmpbge $RA,$RB,$RC", []>; //Compare byte
319 def CMPBGEi  : OFormL<0x10, 0x0F, "cmpbge $RA,$L,$RC", []>; //Compare byte
320 def CMPEQ    : OForm< 0x10, 0x2D, "cmpeq $RA,$RB,$RC", []>; //Compare signed quadword equal
321 def CMPEQi   : OFormL<0x10, 0x2D, "cmpeq $RA,$L,$RC", []>; //Compare signed quadword equal
322 def CMPLE    : OForm< 0x10, 0x6D, "cmple $RA,$RB,$RC", []>; //Compare signed quadword less than or equal
323 def CMPLEi   : OFormL<0x10, 0x6D, "cmple $RA,$L,$RC", []>; //Compare signed quadword less than or equal
324 def CMPLT    : OForm< 0x10, 0x4D, "cmplt $RA,$RB,$RC", []>; //Compare signed quadword less than
325 def CMPLTi   : OFormL<0x10, 0x4D, "cmplt $RA,$L,$RC", []>; //Compare signed quadword less than
326 def CMPULE   : OForm< 0x10, 0x3D, "cmpule $RA,$RB,$RC", []>; //Compare unsigned quadword less than or equal
327 def CMPULEi  : OFormL<0x10, 0x3D, "cmpule $RA,$L,$RC", []>; //Compare unsigned quadword less than or equal
328 def CMPULT   : OForm< 0x10, 0x1D, "cmpult $RA,$RB,$RC", []>; //Compare unsigned quadword less than
329 def CMPULTi  : OFormL<0x10, 0x1D, "cmpult $RA,$L,$RC", []>; //Compare unsigned quadword less than
330
331 //Comparison, FP
332 def CMPTEQ : FPForm<0x16, 0x0A5, "cmpteq/su $RA,$RB,$RC">;  //Compare T_floating equal
333 def CMPTLE : FPForm<0x16, 0x0A7, "cmptle/su $RA,$RB,$RC">;  //Compare T_floating less than or equal
334 def CMPTLT : FPForm<0x16, 0x0A6, "cmptlt/su $RA,$RB,$RC">;  //Compare T_floating less than
335 def CMPTUN : FPForm<0x16, 0x0A4, "cmptun/su $RA,$RB,$RC">;  //Compare T_floating unordered
336
337 //There are in the Multimedia extentions, so let's not use them yet
338 //def MAXSB8  : OForm<0x1C, 0x3E, "MAXSB8 $RA,$RB,$RC">; //Vector signed byte maximum
339 //def MAXSW4 : OForm< 0x1C, 0x3F, "MAXSW4 $RA,$RB,$RC">; //Vector signed word maximum
340 //def MAXUB8  : OForm<0x1C, 0x3C, "MAXUB8 $RA,$RB,$RC">; //Vector unsigned byte maximum
341 //def MAXUW4 : OForm< 0x1C, 0x3D, "MAXUW4 $RA,$RB,$RC">; //Vector unsigned word maximum
342 //def MINSB8 : OForm< 0x1C, 0x38, "MINSB8 $RA,$RB,$RC">; //Vector signed byte minimum
343 //def MINSW4 : OForm< 0x1C, 0x39, "MINSW4 $RA,$RB,$RC">; //Vector signed word minimum
344 //def MINUB8 : OForm< 0x1C, 0x3A, "MINUB8 $RA,$RB,$RC">; //Vector unsigned byte minimum
345 //def MINUW4 : OForm< 0x1C, 0x3B, "MINUW4 $RA,$RB,$RC">; //Vector unsigned word minimum
346 //def PERR : OForm< 0x1C, 0x31, "PERR $RA,$RB,$RC">; //Pixel error
347 //def PKLB : OForm< 0x1C, 0x37, "PKLB $RA,$RB,$RC">; //Pack longwords to bytes
348 //def PKWB  : OForm<0x1C, 0x36, "PKWB $RA,$RB,$RC">; //Pack words to bytes
349 //def UNPKBL : OForm< 0x1C, 0x35, "UNPKBL $RA,$RB,$RC">; //Unpack bytes to longwords
350 //def UNPKBW : OForm< 0x1C, 0x34, "UNPKBW $RA,$RB,$RC">; //Unpack bytes to words
351
352 //End operate
353
354 let isReturn = 1, isTerminator = 1 in 
355   def RET : MbrForm< 0x1A, 0x02, (ops GPRC:$RD, GPRC:$RS, s64imm:$DISP), "ret $RD,($RS),$DISP">; //Return from subroutine
356 //DAG Version:
357 let isReturn = 1, isTerminator = 1, Ra = 31, Rb = 26, disp = 1, Uses = [R26] in 
358   def RETDAG : MbrForm< 0x1A, 0x02, (ops), "ret $$31,($$26),1">; //Return from subroutine
359
360 def JMP : MbrForm< 0x1A, 0x00, (ops GPRC:$RD, GPRC:$RS, GPRC:$DISP), "jmp $RD,($RS),$DISP">; //Jump
361 let isCall = 1,
362     Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R16, R17, R18, R19,
363             R20, R21, R22, R23, R24, R25, R27, R28, R29,
364             F0, F1,
365             F10, F11, F12, F13, F14, F15, F16, F17, F18, F19,
366             F20, F21, F22, F23, F24, F25, F26, F27, F28, F29, F30], Uses = [R29] in {
367     def JSR : MbrForm< 0x1A, 0x01, (ops GPRC:$RD, GPRC:$RS, s14imm:$DISP), "jsr $RD,($RS),$DISP">; //Jump to subroutine
368     def BSR : BForm<0x34, "bsr $RA,$DISP">; //Branch to subroutine
369 }
370 let isCall = 1,
371     Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R16, R17, R18, R19,
372             R20, R21, R22, R23, R24, R25, R26, R27, R28, R29,
373             F0, F1,
374             F10, F11, F12, F13, F14, F15, F16, F17, F18, F19,
375             F20, F21, F22, F23, F24, F25, F26, F27, F28, F29, F30], Uses = [R27, R29] in {
376     def JSRDAG : MbrForm< 0x1A, 0x01, (ops ), "jsr $$26,($$27),0">; //Jump to subroutine
377 }
378 let isCall = 1, Defs = [R24, R25, R27, R28], Uses = [R24, R25] in
379   def JSRs : MbrForm< 0x1A, 0x01, (ops GPRC:$RD, GPRC:$RS, s14imm:$DISP), "jsr $RD,($RS),$DISP">; //Jump to div or rem
380
381 def JSR_COROUTINE : MbrForm< 0x1A, 0x03, (ops GPRC:$RD, GPRC:$RS, s14imm:$DISP), "jsr_coroutine $RD,($RS),$DISP">; //Jump to subroutine return
382 def BR : BForm<0x30, "br $RA,$DISP">; //Branch
383
384 def BR_DAG : BFormD<0x30, "br $$31,$DISP">; //Branch
385
386 //Stores, int
387 def STB : MForm<0x0E, "stb $RA,$DISP($RB)">; // Store byte
388 def STW : MForm<0x0D, "stw $RA,$DISP($RB)">; // Store word
389 def STL : MForm<0x2C, "stl $RA,$DISP($RB)">; // Store longword
390 def STQ : MForm<0x2D, "stq $RA,$DISP($RB)">; //Store quadword
391
392 //Loads, int
393 def LDL : MForm<0x28,  "ldl $RA,$DISP($RB)">; // Load sign-extended longword
394 def LDQ : MForm<0x29,  "ldq $RA,$DISP($RB)">; //Load quadword
395 def LDBU : MForm<0x0A, "ldbu $RA,$DISP($RB)">; //Load zero-extended byte
396 def LDWU : MForm<0x0C, "ldwu $RA,$DISP($RB)">; //Load zero-extended word
397
398 //Stores, float
399 def STS : MForm<0x26, "sts $RA,$DISP($RB)">; //Store S_floating
400 def STT : MForm<0x27, "stt $RA,$DISP($RB)">; //Store T_floating
401
402 //Loads, float
403 def LDS : MForm<0x22, "lds $RA,$DISP($RB)">; //Load S_floating
404 def LDT : MForm<0x23, "ldt $RA,$DISP($RB)">; //Load T_floating
405
406 //Load address
407 def LDA : MForm<0x08,  "lda $RA,$DISP($RB)">;  //Load address
408 def LDAH : MForm<0x09, "ldah $RA,$DISP($RB)">;  //Load address high
409
410
411 //Loads, int, Rellocated Low form
412 def LDLr : MForm<0x28,  "ldl $RA,$DISP($RB)\t\t!gprellow">; // Load sign-extended longword
413 def LDQr : MForm<0x29,  "ldq $RA,$DISP($RB)\t\t!gprellow">; //Load quadword
414 def LDBUr : MForm<0x0A, "ldbu $RA,$DISP($RB)\t\t!gprellow">; //Load zero-extended byte
415 def LDWUr : MForm<0x0C, "ldwu $RA,$DISP($RB)\t\t!gprellow">; //Load zero-extended word
416
417 //Loads, float, Rellocated Low form
418 def LDSr : MForm<0x22, "lds $RA,$DISP($RB)\t\t!gprellow">; //Load S_floating
419 def LDTr : MForm<0x23, "ldt $RA,$DISP($RB)\t\t!gprellow">; //Load T_floating
420
421 //Load address, rellocated low and high form
422 def LDAr : MForm<0x08,  "lda $RA,$DISP($RB)\t\t!gprellow">;  //Load address
423 def LDAHr : MForm<0x09, "ldah $RA,$DISP($RB)\t\t!gprelhigh">;  //Load address high
424
425 //load address, rellocated gpdist form
426 def LDAg : MgForm<0x08,  "lda $RA,0($RB)\t\t!gpdisp!$NUM">;  //Load address
427 def LDAHg : MgForm<0x09, "ldah $RA,0($RB)\t\t!gpdisp!$NUM">;  //Load address
428
429
430 //Load quad, rellocated literal form
431 def LDQl : MForm<0x29, "ldq $RA,$DISP($RB)\t\t!literal">; //Load quadword
432
433 //Stores, int
434 def STBr : MForm<0x0E, "stb $RA,$DISP($RB)\t\t!gprellow">; // Store byte
435 def STWr : MForm<0x0D, "stw $RA,$DISP($RB)\t\t!gprellow">; // Store word
436 def STLr : MForm<0x2C, "stl $RA,$DISP($RB)\t\t!gprellow">; // Store longword
437 def STQr : MForm<0x2D, "stq $RA,$DISP($RB)\t\t!gprellow">; //Store quadword
438
439 //Stores, float
440 def STSr : MForm<0x26, "sts $RA,$DISP($RB)\t\t!gprellow">; //Store S_floating
441 def STTr : MForm<0x27, "stt $RA,$DISP($RB)\t\t!gprellow">; //Store T_floating
442
443
444 //Branches, int
445 def BEQ : BForm<0x39,  "beq $RA,$DISP">; //Branch if = zero
446 def BGE : BForm<0x3E,  "bge $RA,$DISP">; //Branch if >= zero
447 def BGT : BForm<0x3F,  "bgt $RA,$DISP">; //Branch if > zero
448 def BLBC : BForm<0x38, "blbc $RA,$DISP">; //Branch if low bit clear
449 def BLBS : BForm<0x3C, "blbs $RA,$DISP">; //Branch if low bit set
450 def BLE : BForm<0x3B,  "ble $RA,$DISP">; //Branch if <= zero
451 def BLT : BForm<0x3A,  "blt $RA,$DISP">; //Branch if < zero
452 def BNE : BForm<0x3D,  "bne $RA,$DISP">; //Branch if != zero
453
454 //Branches, float
455 def FBEQ : FBForm<0x31, "fbeq $RA,$DISP">; //Floating branch if =  zero
456 def FBGE : FBForm<0x36, "fbge $RA,$DISP">; //Floating branch if >= zero
457 def FBGT : FBForm<0x37, "fbgt $RA,$DISP">; //Floating branch if > zero
458 def FBLE : FBForm<0x33, "fble $RA,$DISP">; //Floating branch if <= zero
459 def FBLT : FBForm<0x32, "fblt $RA,$DISP">; //Floating branch if < zero
460 def FBNE : FBForm<0x35, "fbne $RA,$DISP">; //Floating branch if != zero
461
462 //Funky Floating point ops
463 def CPYS  : FPForm<0x17, 0x020, "cpys $RA,$RB,$RC">;  //Copy sign
464 def CPYSE : FPForm<0x17, 0x022, "cpyse $RA,$RB,$RC">; //Copy sign and exponent
465 def CPYSN : FPForm<0x17, 0x021, "cpysn $RA,$RB,$RC">; //Copy sign negate
466
467 //Basic Floating point ops
468 def ADDS  : FPForm<0x16, 0x580, "adds/su $RA,$RB,$RC">;  //Add S_floating
469 def ADDT  : FPForm<0x16, 0x5A0, "addt/su $RA,$RB,$RC">;  //Add T_floating
470 def SUBS  : FPForm<0x16, 0x581, "subs/su $RA,$RB,$RC">;  //Subtract S_floating
471 def SUBT  : FPForm<0x16, 0x5A1, "subt/su $RA,$RB,$RC">;  //Subtract T_floating
472 def DIVS  : FPForm<0x16, 0x583, "divs/su $RA,$RB,$RC">;  //Divide S_floating
473 def DIVT  : FPForm<0x16, 0x5A3, "divt/su $RA,$RB,$RC">;  //Divide T_floating
474 def MULS  : FPForm<0x16, 0x582, "muls/su $RA,$RB,$RC">;  //Multiply S_floating
475 def MULT  : FPForm<0x16, 0x5A2, "mult/su $RA,$RB,$RC">;  //Multiply T_floating
476 def SQRTS : FPForm<0x14, 0x58B, "sqrts/su $RA,$RB,$RC">;  //Square root S_floating
477 def SQRTT : FPForm<0x14, 0x5AB, "sqrtt/su $RA,$RB,$RC">;  //Square root T_floating
478
479 //INT reg to FP reg and back again
480 //not supported on 21164
481 def FTOIS : FPForm<0x1C, 0x078, "ftois $RA,$RC">; //Floating to integer move, S_floating
482 def FTOIT : FPForm<0x1C, 0x070, "ftoit $RA,$RC">; //Floating to integer move, T_floating
483 def ITOFS : FPForm<0x14, 0x004, "itofs $RA,$RC">; //Integer to floating move, S_floating
484 def ITOFT : FPForm<0x14, 0x024, "itoft $RA,$RC">; //Integer to floating move, T_floating
485
486 //CVTLQ F-P 17.010 Convert longword to quadword
487 //CVTQL F-P 17.030 Convert quadword to longword
488 //These use SW completion, may not have function code for that set right (matters for JIT)
489 def CVTQS : FPForm<0x16, 0x0BC, "cvtqs $RB,$RC">; //Convert quadword to S_floating
490 def CVTQT : FPForm<0x16, 0x0BE, "cvtqt $RB,$RC">; //Convert quadword to T_floating
491 def CVTST : FPForm<0x16, 0x2AC, "cvtsts $RB,$RC">; //Convert S_floating to T_floating
492 def CVTTQ : FPForm<0x16, 0x52F, "cvttq/svc $RB,$RC">; //Convert T_floating to quadword
493 def CVTTS : FPForm<0x16, 0x5AC, "cvtts/su $RB,$RC">; //Convert T_floating to S_floating
494
495 //S_floating : IEEE Single
496 //T_floating : IEEE Double
497
498 //Mnemonic Format Opcode Description
499
500 //CALL_PAL Pcd 00 Trap to PALcode
501 //ECB Mfc 18.E800 Evict cache block
502 //EXCB Mfc 18.0400 Exception barrier
503 //FETCH Mfc 18.8000 Prefetch data
504 //FETCH_M Mfc 18.A000 Prefetch data, modify intent
505
506 //LDL_L Mem 2A Load sign-extended longword locked
507 //LDQ_L Mem 2B Load quadword locked
508 //LDQ_U Mem 0B Load unaligned quadword
509 //MB Mfc 18.4000 Memory barrier
510 //RPCC Mfc 18.C000 Read process cycle counter
511
512 //STL_C Mem 2E Store longword conditional
513 //STQ_C Mem 2F Store quadword conditional
514 //STQ_U Mem 0F Store unaligned quadword
515
516 //TRAPB Mfc 18.0000 Trap barrier
517 //WH64 Mfc 18.F800 Write hint \14 64 bytes
518 //WMB Mfc 18.4400 Write memory barrier
519
520
521 //MF_FPCR F-P 17.025 Move from FPCR
522 //MT_FPCR F-P 17.024 Move to FPCR
523
524 def : Pat<(i64 immSExt16:$imm),
525           (LDA immSExt16:$imm, R31)>;