fix PR3538 for ARM.
[oota-llvm.git] / lib / Target / ARM / ARMInstrVFP.td
1 //===- ARMInstrVFP.td - VFP support for ARM -------------------------------===//
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 // This file describes the ARM VFP instruction set.
11 //
12 //===----------------------------------------------------------------------===//
13
14 def SDT_FTOI :
15 SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
16 def SDT_ITOF :
17 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
18 def SDT_CMPFP0 :
19 SDTypeProfile<0, 1, [SDTCisFP<0>]>;
20 def SDT_FMDRR :
21 SDTypeProfile<1, 2, [SDTCisVT<0, f64>, SDTCisVT<1, i32>,
22                      SDTCisSameAs<1, 2>]>;
23
24 def arm_ftoui  : SDNode<"ARMISD::FTOUI",  SDT_FTOI>;
25 def arm_ftosi  : SDNode<"ARMISD::FTOSI",  SDT_FTOI>;
26 def arm_sitof  : SDNode<"ARMISD::SITOF",  SDT_ITOF>;
27 def arm_uitof  : SDNode<"ARMISD::UITOF",  SDT_ITOF>;
28 def arm_fmstat : SDNode<"ARMISD::FMSTAT", SDTNone, [SDNPInFlag,SDNPOutFlag]>;
29 def arm_cmpfp  : SDNode<"ARMISD::CMPFP",  SDT_ARMCmp, [SDNPOutFlag]>;
30 def arm_cmpfp0 : SDNode<"ARMISD::CMPFPw0",SDT_CMPFP0, [SDNPOutFlag]>;
31 def arm_fmdrr  : SDNode<"ARMISD::FMDRR",  SDT_FMDRR>;
32
33 //===----------------------------------------------------------------------===//
34 //  Load / store Instructions.
35 //
36
37 let canFoldAsLoad = 1 in {
38 def FLDD  : ADI5<0b1101, 0b01, (outs DPR:$dst), (ins addrmode5:$addr),
39                  "fldd", " $dst, $addr",
40                  [(set DPR:$dst, (load addrmode5:$addr))]>;
41
42 def FLDS  : ASI5<0b1101, 0b01, (outs SPR:$dst), (ins addrmode5:$addr),
43                  "flds", " $dst, $addr",
44                  [(set SPR:$dst, (load addrmode5:$addr))]>;
45 } // canFoldAsLoad
46
47 def FSTD  : ADI5<0b1101, 0b00, (outs), (ins DPR:$src, addrmode5:$addr),
48                  "fstd", " $src, $addr",
49                  [(store DPR:$src, addrmode5:$addr)]>;
50
51 def FSTS  : ASI5<0b1101, 0b00, (outs), (ins SPR:$src, addrmode5:$addr),
52                  "fsts", " $src, $addr",
53                  [(store SPR:$src, addrmode5:$addr)]>;
54
55 //===----------------------------------------------------------------------===//
56 //  Load / store multiple Instructions.
57 //
58
59 let mayLoad = 1 in {
60 def FLDMD : AXDI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$dst1,
61                            variable_ops),
62                   "fldm${addr:submode}d${p} ${addr:base}, $dst1",
63                   []> {
64   let Inst{20} = 1;
65 }
66
67 def FLDMS : AXSI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$dst1,
68                            variable_ops),
69                   "fldm${addr:submode}s${p} ${addr:base}, $dst1",
70                   []> {
71   let Inst{20} = 1;
72 }
73 }
74
75 let mayStore = 1 in {
76 def FSTMD : AXDI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$src1,
77                            variable_ops),
78                  "fstm${addr:submode}d${p} ${addr:base}, $src1",
79                  []> {
80   let Inst{20} = 0;
81 }
82
83 def FSTMS : AXSI5<(outs), (ins addrmode5:$addr, pred:$p, reglist:$src1,
84                            variable_ops),
85                  "fstm${addr:submode}s${p} ${addr:base}, $src1",
86                  []> {
87   let Inst{20} = 0;
88 }
89 } // mayStore
90
91 // FLDMX, FSTMX - mixing S/D registers for pre-armv6 cores
92
93 //===----------------------------------------------------------------------===//
94 // FP Binary Operations.
95 //
96
97 def FADDD  : ADbI<0b11100011, (outs DPR:$dst), (ins DPR:$a, DPR:$b),
98                  "faddd", " $dst, $a, $b",
99                  [(set DPR:$dst, (fadd DPR:$a, DPR:$b))]>;
100
101 def FADDS  : ASbI<0b11100011, (outs SPR:$dst), (ins SPR:$a, SPR:$b),
102                  "fadds", " $dst, $a, $b",
103                  [(set SPR:$dst, (fadd SPR:$a, SPR:$b))]>;
104
105 // These are encoded as unary instructions.
106 def FCMPED : ADuI<0b11101011, 0b0100, 0b1100, (outs), (ins DPR:$a, DPR:$b),
107                  "fcmped", " $a, $b",
108                  [(arm_cmpfp DPR:$a, DPR:$b)]>;
109
110 def FCMPES : ASuI<0b11101011, 0b0100, 0b1100, (outs), (ins SPR:$a, SPR:$b),
111                  "fcmpes", " $a, $b",
112                  [(arm_cmpfp SPR:$a, SPR:$b)]>;
113
114 def FDIVD  : ADbI<0b11101000, (outs DPR:$dst), (ins DPR:$a, DPR:$b),
115                  "fdivd", " $dst, $a, $b",
116                  [(set DPR:$dst, (fdiv DPR:$a, DPR:$b))]>;
117
118 def FDIVS  : ASbI<0b11101000, (outs SPR:$dst), (ins SPR:$a, SPR:$b),
119                  "fdivs", " $dst, $a, $b",
120                  [(set SPR:$dst, (fdiv SPR:$a, SPR:$b))]>;
121
122 def FMULD  : ADbI<0b11100010, (outs DPR:$dst), (ins DPR:$a, DPR:$b),
123                  "fmuld", " $dst, $a, $b",
124                  [(set DPR:$dst, (fmul DPR:$a, DPR:$b))]>;
125
126 def FMULS  : ASbI<0b11100010, (outs SPR:$dst), (ins SPR:$a, SPR:$b),
127                  "fmuls", " $dst, $a, $b",
128                  [(set SPR:$dst, (fmul SPR:$a, SPR:$b))]>;
129                  
130 def FNMULD  : ADbI<0b11100010, (outs DPR:$dst), (ins DPR:$a, DPR:$b),
131                   "fnmuld", " $dst, $a, $b",
132                   [(set DPR:$dst, (fneg (fmul DPR:$a, DPR:$b)))]> {
133   let Inst{6} = 1;
134 }
135
136 def FNMULS  : ASbI<0b11100010, (outs SPR:$dst), (ins SPR:$a, SPR:$b),
137                   "fnmuls", " $dst, $a, $b",
138                   [(set SPR:$dst, (fneg (fmul SPR:$a, SPR:$b)))]> {
139   let Inst{6} = 1;
140 }
141
142 // Match reassociated forms only if not sign dependent rounding.
143 def : Pat<(fmul (fneg DPR:$a), DPR:$b),
144           (FNMULD DPR:$a, DPR:$b)>, Requires<[NoHonorSignDependentRounding]>;
145 def : Pat<(fmul (fneg SPR:$a), SPR:$b),
146           (FNMULS SPR:$a, SPR:$b)>, Requires<[NoHonorSignDependentRounding]>;
147
148
149 def FSUBD  : ADbI<0b11100011, (outs DPR:$dst), (ins DPR:$a, DPR:$b),
150                  "fsubd", " $dst, $a, $b",
151                  [(set DPR:$dst, (fsub DPR:$a, DPR:$b))]> {
152   let Inst{6} = 1;
153 }
154
155 def FSUBS  : ASbI<0b11100011, (outs SPR:$dst), (ins SPR:$a, SPR:$b),
156                  "fsubs", " $dst, $a, $b",
157                  [(set SPR:$dst, (fsub SPR:$a, SPR:$b))]> {
158   let Inst{6} = 1;
159 }
160
161 //===----------------------------------------------------------------------===//
162 // FP Unary Operations.
163 //
164
165 def FABSD  : ADuI<0b11101011, 0b0000, 0b1100, (outs DPR:$dst), (ins DPR:$a),
166                  "fabsd", " $dst, $a",
167                  [(set DPR:$dst, (fabs DPR:$a))]>;
168
169 def FABSS  : ASuI<0b11101011, 0b0000, 0b1100, (outs SPR:$dst), (ins SPR:$a),
170                  "fabss", " $dst, $a",
171                  [(set SPR:$dst, (fabs SPR:$a))]>;
172
173 def FCMPEZD : ADuI<0b11101011, 0b0101, 0b1100, (outs), (ins DPR:$a),
174                   "fcmpezd", " $a",
175                   [(arm_cmpfp0 DPR:$a)]>;
176
177 def FCMPEZS : ASuI<0b11101011, 0b0101, 0b1100, (outs), (ins SPR:$a),
178                   "fcmpezs", " $a",
179                   [(arm_cmpfp0 SPR:$a)]>;
180
181 def FCVTDS : ASuI<0b11101011, 0b0111, 0b1100, (outs DPR:$dst), (ins SPR:$a),
182                  "fcvtds", " $dst, $a",
183                  [(set DPR:$dst, (fextend SPR:$a))]>;
184
185 // Special case encoding: bits 11-8 is 0b1011.
186 def FCVTSD : AI<(outs SPR:$dst), (ins DPR:$a), VFPUnaryFrm,
187                  "fcvtsd", " $dst, $a",
188                  [(set SPR:$dst, (fround DPR:$a))]> {
189   let Inst{27-23} = 0b11101;
190   let Inst{21-16} = 0b110111;
191   let Inst{11-8}  = 0b1011;
192   let Inst{7-4}   = 0b1100;
193 }
194
195 def FCPYD  : ADuI<0b11101011, 0b0000, 0b0100, (outs DPR:$dst), (ins DPR:$a),
196                  "fcpyd", " $dst, $a", []>;
197
198 def FCPYS  : ASuI<0b11101011, 0b0000, 0b0100, (outs SPR:$dst), (ins SPR:$a),
199                  "fcpys", " $dst, $a", []>;
200
201 def FNEGD  : ADuI<0b11101011, 0b0001, 0b0100, (outs DPR:$dst), (ins DPR:$a),
202                  "fnegd", " $dst, $a",
203                  [(set DPR:$dst, (fneg DPR:$a))]>;
204
205 def FNEGS  : ASuI<0b11101011, 0b0001, 0b0100, (outs SPR:$dst), (ins SPR:$a),
206                  "fnegs", " $dst, $a",
207                  [(set SPR:$dst, (fneg SPR:$a))]>;
208
209 def FSQRTD  : ADuI<0b11101011, 0b0001, 0b1100, (outs DPR:$dst), (ins DPR:$a),
210                  "fsqrtd", " $dst, $a",
211                  [(set DPR:$dst, (fsqrt DPR:$a))]>;
212
213 def FSQRTS  : ASuI<0b11101011, 0b0001, 0b1100, (outs SPR:$dst), (ins SPR:$a),
214                  "fsqrts", " $dst, $a",
215                  [(set SPR:$dst, (fsqrt SPR:$a))]>;
216
217 //===----------------------------------------------------------------------===//
218 // FP <-> GPR Copies.  Int <-> FP Conversions.
219 //
220
221 def FMRS   : AVConv2I<0b11100001, 0b1010, (outs GPR:$dst), (ins SPR:$src),
222                  "fmrs", " $dst, $src",
223                  [(set GPR:$dst, (bitconvert SPR:$src))]>;
224
225 def FMSR   : AVConv4I<0b11100000, 0b1010, (outs SPR:$dst), (ins GPR:$src),
226                  "fmsr", " $dst, $src",
227                  [(set SPR:$dst, (bitconvert GPR:$src))]>;
228
229 def FMRRD  : AVConv3I<0b11000101, 0b1011,
230                       (outs GPR:$dst1, GPR:$dst2), (ins DPR:$src),
231                  "fmrrd", " $dst1, $dst2, $src",
232                  [/* FIXME: Can't write pattern for multiple result instr*/]>;
233
234 // FMDHR: GPR -> SPR
235 // FMDLR: GPR -> SPR
236
237 def FMDRR : AVConv5I<0b11000100, 0b1011,
238                      (outs DPR:$dst), (ins GPR:$src1, GPR:$src2),
239                 "fmdrr", " $dst, $src1, $src2",
240                 [(set DPR:$dst, (arm_fmdrr GPR:$src1, GPR:$src2))]>;
241
242 // FMRDH: SPR -> GPR
243 // FMRDL: SPR -> GPR
244 // FMRRS: SPR -> GPR
245 // FMRX : SPR system reg -> GPR
246
247 // FMSRR: GPR -> SPR
248
249 // FMXR: GPR -> VFP Sstem reg
250
251
252 // Int to FP:
253
254 def FSITOD : AVConv1I<0b11101011, 0b1000, 0b1011, (outs DPR:$dst), (ins SPR:$a),
255                  "fsitod", " $dst, $a",
256                  [(set DPR:$dst, (arm_sitof SPR:$a))]> {
257   let Inst{7} = 1;
258 }
259
260 def FSITOS : AVConv1I<0b11101011, 0b1000, 0b1010, (outs SPR:$dst), (ins SPR:$a),
261                  "fsitos", " $dst, $a",
262                  [(set SPR:$dst, (arm_sitof SPR:$a))]> {
263   let Inst{7} = 1;
264 }
265
266 def FUITOD : AVConv1I<0b11101011, 0b1000, 0b1011, (outs DPR:$dst), (ins SPR:$a),
267                  "fuitod", " $dst, $a",
268                  [(set DPR:$dst, (arm_uitof SPR:$a))]>;
269
270 def FUITOS : AVConv1I<0b11101011, 0b1000, 0b1010, (outs SPR:$dst), (ins SPR:$a),
271                  "fuitos", " $dst, $a",
272                  [(set SPR:$dst, (arm_uitof SPR:$a))]>;
273
274 // FP to Int:
275 // Always set Z bit in the instruction, i.e. "round towards zero" variants.
276
277 def FTOSIZD : AVConv1I<0b11101011, 0b1101, 0b1011,
278                        (outs SPR:$dst), (ins DPR:$a),
279                  "ftosizd", " $dst, $a",
280                  [(set SPR:$dst, (arm_ftosi DPR:$a))]> {
281   let Inst{7} = 1; // Z bit
282 }
283
284 def FTOSIZS : AVConv1I<0b11101011, 0b1101, 0b1010,
285                        (outs SPR:$dst), (ins SPR:$a),
286                  "ftosizs", " $dst, $a",
287                  [(set SPR:$dst, (arm_ftosi SPR:$a))]> {
288   let Inst{7} = 1; // Z bit
289 }
290
291 def FTOUIZD : AVConv1I<0b11101011, 0b1100, 0b1011,
292                        (outs SPR:$dst), (ins DPR:$a),
293                  "ftouizd", " $dst, $a",
294                  [(set SPR:$dst, (arm_ftoui DPR:$a))]> {
295   let Inst{7} = 1; // Z bit
296 }
297
298 def FTOUIZS : AVConv1I<0b11101011, 0b1100, 0b1010,
299                        (outs SPR:$dst), (ins SPR:$a),
300                  "ftouizs", " $dst, $a",
301                  [(set SPR:$dst, (arm_ftoui SPR:$a))]> {
302   let Inst{7} = 1; // Z bit
303 }
304
305 //===----------------------------------------------------------------------===//
306 // FP FMA Operations.
307 //
308
309 def FMACD : ADbI<0b11100000, (outs DPR:$dst), (ins DPR:$dstin, DPR:$a, DPR:$b),
310                 "fmacd", " $dst, $a, $b",
311                 [(set DPR:$dst, (fadd (fmul DPR:$a, DPR:$b), DPR:$dstin))]>,
312                 RegConstraint<"$dstin = $dst">;
313
314 def FMACS : ASbI<0b11100000, (outs SPR:$dst), (ins SPR:$dstin, SPR:$a, SPR:$b),
315                 "fmacs", " $dst, $a, $b",
316                 [(set SPR:$dst, (fadd (fmul SPR:$a, SPR:$b), SPR:$dstin))]>,
317                 RegConstraint<"$dstin = $dst">;
318
319 def FMSCD : ADbI<0b11100001, (outs DPR:$dst), (ins DPR:$dstin, DPR:$a, DPR:$b),
320                 "fmscd", " $dst, $a, $b",
321                 [(set DPR:$dst, (fsub (fmul DPR:$a, DPR:$b), DPR:$dstin))]>,
322                 RegConstraint<"$dstin = $dst">;
323
324 def FMSCS : ASbI<0b11100001, (outs SPR:$dst), (ins SPR:$dstin, SPR:$a, SPR:$b),
325                 "fmscs", " $dst, $a, $b",
326                 [(set SPR:$dst, (fsub (fmul SPR:$a, SPR:$b), SPR:$dstin))]>,
327                 RegConstraint<"$dstin = $dst">;
328
329 def FNMACD : ADbI<0b11100000, (outs DPR:$dst), (ins DPR:$dstin, DPR:$a, DPR:$b),
330                  "fnmacd", " $dst, $a, $b",
331              [(set DPR:$dst, (fadd (fneg (fmul DPR:$a, DPR:$b)), DPR:$dstin))]>,
332                 RegConstraint<"$dstin = $dst"> {
333   let Inst{6} = 1;
334 }
335
336 def FNMACS : ASbI<0b11100000, (outs SPR:$dst), (ins SPR:$dstin, SPR:$a, SPR:$b),
337                 "fnmacs", " $dst, $a, $b",
338              [(set SPR:$dst, (fadd (fneg (fmul SPR:$a, SPR:$b)), SPR:$dstin))]>,
339                 RegConstraint<"$dstin = $dst"> {
340   let Inst{6} = 1;
341 }
342
343 def FNMSCD : ADbI<0b11100001, (outs DPR:$dst), (ins DPR:$dstin, DPR:$a, DPR:$b),
344                  "fnmscd", " $dst, $a, $b",
345              [(set DPR:$dst, (fsub (fneg (fmul DPR:$a, DPR:$b)), DPR:$dstin))]>,
346                 RegConstraint<"$dstin = $dst"> {
347   let Inst{6} = 1;
348 }
349
350 def FNMSCS : ASbI<0b11100001, (outs SPR:$dst), (ins SPR:$dstin, SPR:$a, SPR:$b),
351                 "fnmscs", " $dst, $a, $b",
352              [(set SPR:$dst, (fsub (fneg (fmul SPR:$a, SPR:$b)), SPR:$dstin))]>,
353                 RegConstraint<"$dstin = $dst"> {
354   let Inst{6} = 1;
355 }
356
357 //===----------------------------------------------------------------------===//
358 // FP Conditional moves.
359 //
360
361 def FCPYDcc  : ADuI<0b11101011, 0b0000, 0b0100,
362                     (outs DPR:$dst), (ins DPR:$false, DPR:$true),
363                     "fcpyd", " $dst, $true",
364                 [/*(set DPR:$dst, (ARMcmov DPR:$false, DPR:$true, imm:$cc))*/]>,
365                     RegConstraint<"$false = $dst">;
366
367 def FCPYScc  : ASuI<0b11101011, 0b0000, 0b0100,
368                     (outs SPR:$dst), (ins SPR:$false, SPR:$true),
369                     "fcpys", " $dst, $true",
370                 [/*(set SPR:$dst, (ARMcmov SPR:$false, SPR:$true, imm:$cc))*/]>,
371                     RegConstraint<"$false = $dst">;
372
373 def FNEGDcc  : ADuI<0b11101011, 0b0001, 0b0100,
374                     (outs DPR:$dst), (ins DPR:$false, DPR:$true),
375                     "fnegd", " $dst, $true",
376                 [/*(set DPR:$dst, (ARMcneg DPR:$false, DPR:$true, imm:$cc))*/]>,
377                     RegConstraint<"$false = $dst">;
378
379 def FNEGScc  : ASuI<0b11101011, 0b0001, 0b0100,
380                     (outs SPR:$dst), (ins SPR:$false, SPR:$true),
381                     "fnegs", " $dst, $true",
382                 [/*(set SPR:$dst, (ARMcneg SPR:$false, SPR:$true, imm:$cc))*/]>,
383                     RegConstraint<"$false = $dst">;
384
385
386 //===----------------------------------------------------------------------===//
387 // Misc.
388 //
389
390 let Defs = [CPSR] in
391 def FMSTAT : AI<(outs), (ins), VFPMiscFrm, "fmstat", "", [(arm_fmstat)]> {
392   let Inst{27-20} = 0b11101111;
393   let Inst{19-16} = 0b0001;
394   let Inst{15-12} = 0b1111;
395   let Inst{11-8}  = 0b1010;
396   let Inst{7}     = 0;
397   let Inst{4}     = 1;
398 }