Evan's patch to avoid FPreg->intreg copy for cvt; store to mem
[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 was developed by Chris Lattner and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the ARM VP instruction set.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // ARM VFP Instruction templates.
16 //
17
18 // ARM Float Instruction
19 class ASI<dag ops, string asm, list<dag> pattern> : AI<ops, asm, pattern> {
20   // TODO: Mark the instructions with the appropriate subtarget info.
21 }
22
23 class ASI5<dag ops, string asm, list<dag> pattern>
24   : I<ops, AddrMode5, Size4Bytes, IndexModeNone, asm, "", pattern> {
25   // TODO: Mark the instructions with the appropriate subtarget info.
26 }
27
28 // ARM Double Instruction
29 class ADI<dag ops, string asm, list<dag> pattern> : AI<ops, asm, pattern> {
30   // TODO: Mark the instructions with the appropriate subtarget info.
31 }
32
33 class ADI5<dag ops, string asm, list<dag> pattern>
34   : I<ops, AddrMode5, Size4Bytes, IndexModeNone, asm, "", pattern> {
35   // TODO: Mark the instructions with the appropriate subtarget info.
36 }
37
38 def SDT_FTOI :
39 SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
40 def SDT_ITOF :
41 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
42 def SDT_CMPFP0 :
43 SDTypeProfile<0, 1, [SDTCisFP<0>]>;
44 def SDT_FMDRR :
45 SDTypeProfile<1, 2, [SDTCisVT<0, f64>, SDTCisVT<1, i32>,
46                      SDTCisSameAs<1, 2>]>;
47
48 def arm_ftoui  : SDNode<"ARMISD::FTOUI", SDT_FTOI>;
49 def arm_ftosi  : SDNode<"ARMISD::FTOSI", SDT_FTOI>;
50 def arm_sitof  : SDNode<"ARMISD::SITOF", SDT_ITOF>;
51 def arm_uitof  : SDNode<"ARMISD::UITOF", SDT_ITOF>;
52 def arm_fmstat : SDNode<"ARMISD::FMSTAT", SDTRet, [SDNPInFlag,SDNPOutFlag]>;
53 def arm_cmpfp  : SDNode<"ARMISD::CMPFP", SDT_ARMCmp, [SDNPOutFlag]>;
54 def arm_cmpfp0 : SDNode<"ARMISD::CMPFPw0", SDT_CMPFP0, [SDNPOutFlag]>;
55 def arm_fmdrr  : SDNode<"ARMISD::FMDRR", SDT_FMDRR>;
56
57 //===----------------------------------------------------------------------===//
58 //  Load / store Instructions.
59 //
60
61 let isLoad = 1 in {
62 def FLDD  : ADI5<(ops DPR:$dst, addrmode5:$addr),
63                  "fldd $dst, $addr",
64                  [(set DPR:$dst, (load addrmode5:$addr))]>;
65
66 def FLDS  : ASI5<(ops SPR:$dst, addrmode5:$addr),
67                  "flds $dst, $addr",
68                  [(set SPR:$dst, (load addrmode5:$addr))]>;
69 } // isLoad
70
71 let isStore = 1 in {
72 def FSTD  : ADI5<(ops DPR:$src, addrmode5:$addr),
73                  "fstd $src, $addr",
74                  [(store DPR:$src, addrmode5:$addr)]>;
75
76 def FSTS  : ASI5<(ops SPR:$src, addrmode5:$addr),
77                  "fsts $src, $addr",
78                  [(store SPR:$src, addrmode5:$addr)]>;
79 } // isStore
80
81 // avoid copying result of FTOUIZ to int reg when we're just storing it
82 let AddedComplexity = 1 in
83 def : ARMPat<(store (i32 (bitconvert SPR:$src)), addrmode5:$addr),
84              (FSTS SPR:$src, addrmode5:$addr)>;
85
86 //===----------------------------------------------------------------------===//
87 //  Load / store multiple Instructions.
88 //
89
90 let isLoad = 1 in {
91 def FLDMD : ADI5<(ops addrmode5:$addr, reglist:$dst1, variable_ops),
92                  "fldm${addr:submode}d ${addr:base}, $dst1",
93                  []>;
94
95 def FLDMS : ASI5<(ops addrmode5:$addr, reglist:$dst1, variable_ops),
96                  "fldm${addr:submode}s ${addr:base}, $dst1",
97                  []>;
98 } // isLoad
99
100 let isStore = 1 in {
101 def FSTMD : ADI5<(ops addrmode5:$addr, reglist:$src1, variable_ops),
102                  "fstm${addr:submode}d ${addr:base}, $src1",
103                  []>;
104
105 def FSTMS : ASI5<(ops addrmode5:$addr, reglist:$src1, variable_ops),
106                  "fstm${addr:submode}s ${addr:base}, $src1",
107                  []>;
108 } // isStore
109
110 // FLDMX, FSTMX - mixing S/D registers for pre-armv6 cores
111
112 //===----------------------------------------------------------------------===//
113 // FP Binary Operations.
114 //
115
116 def FADDD  : ADI<(ops DPR:$dst, DPR:$a, DPR:$b),
117                  "faddd $dst, $a, $b",
118                  [(set DPR:$dst, (fadd DPR:$a, DPR:$b))]>;
119
120 def FADDS  : ASI<(ops SPR:$dst, SPR:$a, SPR:$b),
121                  "fadds $dst, $a, $b",
122                  [(set SPR:$dst, (fadd SPR:$a, SPR:$b))]>;
123
124 def FCMPED : ADI<(ops DPR:$a, DPR:$b),
125                  "fcmped $a, $b",
126                  [(arm_cmpfp DPR:$a, DPR:$b)]>;
127
128 def FCMPES : ASI<(ops SPR:$a, SPR:$b),
129                  "fcmpes $a, $b",
130                  [(arm_cmpfp SPR:$a, SPR:$b)]>;
131
132 def FDIVD  : ADI<(ops DPR:$dst, DPR:$a, DPR:$b),
133                  "fdivd $dst, $a, $b",
134                  [(set DPR:$dst, (fdiv DPR:$a, DPR:$b))]>;
135
136 def FDIVS  : ASI<(ops SPR:$dst, SPR:$a, SPR:$b),
137                  "fdivs $dst, $a, $b",
138                  [(set SPR:$dst, (fdiv SPR:$a, SPR:$b))]>;
139
140 def FMULD  : ADI<(ops DPR:$dst, DPR:$a, DPR:$b),
141                  "fmuld $dst, $a, $b",
142                  [(set DPR:$dst, (fmul DPR:$a, DPR:$b))]>;
143
144 def FMULS  : ASI<(ops SPR:$dst, SPR:$a, SPR:$b),
145                  "fmuls $dst, $a, $b",
146                  [(set SPR:$dst, (fmul SPR:$a, SPR:$b))]>;
147                  
148 def FNMULD  : ADI<(ops DPR:$dst, DPR:$a, DPR:$b),
149                   "fnmuld $dst, $a, $b",
150                   [(set DPR:$dst, (fneg (fmul DPR:$a, DPR:$b)))]>;
151
152 def FNMULS  : ASI<(ops SPR:$dst, SPR:$a, SPR:$b),
153                   "fnmuls $dst, $a, $b",
154                   [(set SPR:$dst, (fneg (fmul SPR:$a, SPR:$b)))]>;
155
156 // Match reassociated forms only if not sign dependent rounding.
157 def : Pat<(fmul (fneg DPR:$a), DPR:$b),
158           (FNMULD DPR:$a, DPR:$b)>, Requires<[NoHonorSignDependentRounding]>;
159 def : Pat<(fmul (fneg SPR:$a), SPR:$b),
160           (FNMULS SPR:$a, SPR:$b)>, Requires<[NoHonorSignDependentRounding]>;
161
162
163 def FSUBD  : ADI<(ops DPR:$dst, DPR:$a, DPR:$b),
164                  "fsubd $dst, $a, $b",
165                  [(set DPR:$dst, (fsub DPR:$a, DPR:$b))]>;
166
167 def FSUBS  : ASI<(ops SPR:$dst, SPR:$a, SPR:$b),
168                  "fsubs $dst, $a, $b",
169                  [(set SPR:$dst, (fsub SPR:$a, SPR:$b))]>;
170
171 //===----------------------------------------------------------------------===//
172 // FP Unary Operations.
173 //
174
175 def FABSD  : ADI<(ops DPR:$dst, DPR:$a),
176                  "fabsd $dst, $a",
177                  [(set DPR:$dst, (fabs DPR:$a))]>;
178
179 def FABSS  : ASI<(ops SPR:$dst, SPR:$a),
180                  "fabss $dst, $a",
181                  [(set SPR:$dst, (fabs SPR:$a))]>;
182
183 def FCMPEZD : ADI<(ops DPR:$a),
184                   "fcmpezd $a",
185                   [(arm_cmpfp0 DPR:$a)]>;
186
187 def FCMPEZS : ASI<(ops SPR:$a),
188                   "fcmpezs $a",
189                   [(arm_cmpfp0 SPR:$a)]>;
190
191 def FCVTDS : ADI<(ops DPR:$dst, SPR:$a),
192                  "fcvtds $dst, $a",
193                  [(set DPR:$dst, (fextend SPR:$a))]>;
194
195 def FCVTSD : ADI<(ops SPR:$dst, DPR:$a),
196                  "fcvtsd $dst, $a",
197                  [(set SPR:$dst, (fround DPR:$a))]>;
198
199 def FCPYD  : ADI<(ops DPR:$dst, DPR:$a),
200                  "fcpyd $dst, $a",
201                  [/*(set DPR:$dst, DPR:$a)*/]>;
202
203 def FCPYS  : ASI<(ops SPR:$dst, SPR:$a),
204                  "fcpys $dst, $a",
205                  [/*(set SPR:$dst, SPR:$a)*/]>;
206
207 def FNEGD  : ADI<(ops DPR:$dst, DPR:$a),
208                  "fnegd $dst, $a",
209                  [(set DPR:$dst, (fneg DPR:$a))]>;
210
211 def FNEGS  : ASI<(ops SPR:$dst, SPR:$a),
212                  "fnegs $dst, $a",
213                  [(set SPR:$dst, (fneg SPR:$a))]>;
214
215 def FSQRTD  : ADI<(ops DPR:$dst, DPR:$a),
216                  "fsqrtd $dst, $a",
217                  [(set DPR:$dst, (fsqrt DPR:$a))]>;
218
219 def FSQRTS  : ASI<(ops SPR:$dst, SPR:$a),
220                  "fsqrts $dst, $a",
221                  [(set SPR:$dst, (fsqrt SPR:$a))]>;
222
223 //===----------------------------------------------------------------------===//
224 // FP <-> GPR Copies.  Int <-> FP Conversions.
225 //
226
227 def IMPLICIT_DEF_SPR : PseudoInst<(ops SPR:$rD),
228                                   "@ IMPLICIT_DEF_SPR $rD",
229                                   [(set SPR:$rD, (undef))]>;
230 def IMPLICIT_DEF_DPR : PseudoInst<(ops DPR:$rD),
231                                   "@ IMPLICIT_DEF_DPR $rD",
232                                   [(set DPR:$rD, (undef))]>;
233
234 def FMRS   : ASI<(ops GPR:$dst, SPR:$src),
235                  "fmrs $dst, $src",
236                  [(set GPR:$dst, (bitconvert SPR:$src))]>;
237
238 def FMSR   : ASI<(ops SPR:$dst, GPR:$src),
239                  "fmsr $dst, $src",
240                  [(set SPR:$dst, (bitconvert GPR:$src))]>;
241
242
243 def FMRRD  : ADI<(ops GPR:$dst1, GPR:$dst2, DPR:$src),
244                  "fmrrd $dst1, $dst2, $src",
245                  [/* FIXME: Can't write pattern for multiple result instr*/]>;
246
247 // FMDHR: GPR -> SPR
248 // FMDLR: GPR -> SPR
249
250 def FMDRR : ADI<(ops DPR:$dst, GPR:$src1, GPR:$src2),
251                 "fmdrr $dst, $src1, $src2",
252                 [(set DPR:$dst, (arm_fmdrr GPR:$src1, GPR:$src2))]>;
253
254 // FMRDH: SPR -> GPR
255 // FMRDL: SPR -> GPR
256 // FMRRS: SPR -> GPR
257 // FMRX : SPR system reg -> GPR
258
259 // FMSRR: GPR -> SPR
260
261
262 def FMSTAT : ASI<(ops), "fmstat", [(arm_fmstat)]>;
263
264 // FMXR: GPR -> VFP Sstem reg
265
266
267 // Int to FP:
268
269 def FSITOD : ADI<(ops DPR:$dst, SPR:$a),
270                  "fsitod $dst, $a",
271                  [(set DPR:$dst, (arm_sitof SPR:$a))]>;
272
273 def FSITOS : ASI<(ops SPR:$dst, SPR:$a),
274                  "fsitos $dst, $a",
275                  [(set SPR:$dst, (arm_sitof SPR:$a))]>;
276
277 def FUITOD : ADI<(ops DPR:$dst, SPR:$a),
278                  "fuitod $dst, $a",
279                  [(set DPR:$dst, (arm_uitof SPR:$a))]>;
280
281 def FUITOS : ASI<(ops SPR:$dst, SPR:$a),
282                  "fuitos $dst, $a",
283                  [(set SPR:$dst, (arm_uitof SPR:$a))]>;
284
285 // FP to Int:
286 // Always set Z bit in the instruction, i.e. "round towards zero" variants.
287
288 def FTOSIZD : ADI<(ops SPR:$dst, DPR:$a),
289                  "ftosizd $dst, $a",
290                  [(set SPR:$dst, (arm_ftosi DPR:$a))]>;
291
292 def FTOSIZS : ASI<(ops SPR:$dst, SPR:$a),
293                  "ftosizs $dst, $a",
294                  [(set SPR:$dst, (arm_ftosi SPR:$a))]>;
295
296 def FTOUIZD : ADI<(ops SPR:$dst, DPR:$a),
297                  "ftouizd $dst, $a",
298                  [(set SPR:$dst, (arm_ftoui DPR:$a))]>;
299
300 def FTOUIZS : ASI<(ops SPR:$dst, SPR:$a),
301                  "ftouizs $dst, $a",
302                  [(set SPR:$dst, (arm_ftoui SPR:$a))]>;
303
304 //===----------------------------------------------------------------------===//
305 // FP FMA Operations.
306 //
307
308 def FMACD : ADI<(ops DPR:$dst, DPR:$dstin, DPR:$a, DPR:$b),
309                 "fmacd $dst, $a, $b",
310                 [(set DPR:$dst, (fadd (fmul DPR:$a, DPR:$b), DPR:$dstin))]>,
311                 RegConstraint<"$dstin = $dst">;
312
313 def FMACS : ASI<(ops SPR:$dst, SPR:$dstin, SPR:$a, SPR:$b),
314                 "fmacs $dst, $a, $b",
315                 [(set SPR:$dst, (fadd (fmul SPR:$a, SPR:$b), SPR:$dstin))]>,
316                 RegConstraint<"$dstin = $dst">;
317
318 def FMSCD : ADI<(ops DPR:$dst, DPR:$dstin, DPR:$a, DPR:$b),
319                 "fmscd $dst, $a, $b",
320                 [(set DPR:$dst, (fsub (fmul DPR:$a, DPR:$b), DPR:$dstin))]>,
321                 RegConstraint<"$dstin = $dst">;
322
323 def FMSCS : ASI<(ops SPR:$dst, SPR:$dstin, SPR:$a, SPR:$b),
324                 "fmscs $dst, $a, $b",
325                 [(set SPR:$dst, (fsub (fmul SPR:$a, SPR:$b), SPR:$dstin))]>,
326                 RegConstraint<"$dstin = $dst">;
327
328 def FNMACD : ADI<(ops DPR:$dst, DPR:$dstin, DPR:$a, DPR:$b),
329                  "fnmacd $dst, $a, $b",
330              [(set DPR:$dst, (fadd (fneg (fmul DPR:$a, DPR:$b)), DPR:$dstin))]>,
331                 RegConstraint<"$dstin = $dst">;
332
333 def FNMACS : ASI<(ops SPR:$dst, SPR:$dstin, SPR:$a, SPR:$b),
334                 "fnmacs $dst, $a, $b",
335              [(set SPR:$dst, (fadd (fneg (fmul SPR:$a, SPR:$b)), SPR:$dstin))]>,
336                 RegConstraint<"$dstin = $dst">;
337
338 def FNMSCD : ADI<(ops DPR:$dst, DPR:$dstin, DPR:$a, DPR:$b),
339                  "fnmscd $dst, $a, $b",
340              [(set DPR:$dst, (fsub (fneg (fmul DPR:$a, DPR:$b)), DPR:$dstin))]>,
341                 RegConstraint<"$dstin = $dst">;
342
343 def FNMSCS : ASI<(ops SPR:$dst, SPR:$dstin, SPR:$a, SPR:$b),
344                 "fnmscs $dst, $a, $b",
345              [(set SPR:$dst, (fsub (fneg (fmul SPR:$a, SPR:$b)), SPR:$dstin))]>,
346                 RegConstraint<"$dstin = $dst">;
347
348 //===----------------------------------------------------------------------===//
349 // FP Conditional moves.
350 //
351
352 def FCPYDcc  : ADI<(ops DPR:$dst, DPR:$false, DPR:$true, CCOp:$cc),
353                    "fcpyd$cc $dst, $true",
354                    [(set DPR:$dst, (ARMcmov DPR:$false, DPR:$true, imm:$cc))]>,
355                    RegConstraint<"$false = $dst">;
356
357 def FCPYScc  : ASI<(ops SPR:$dst, SPR:$false, SPR:$true, CCOp:$cc),
358                    "fcpys$cc $dst, $true",
359                    [(set SPR:$dst, (ARMcmov SPR:$false, SPR:$true, imm:$cc))]>,
360                    RegConstraint<"$false = $dst">;
361
362 def FNEGDcc  : ADI<(ops DPR:$dst, DPR:$false, DPR:$true, CCOp:$cc),
363                    "fnegd$cc $dst, $true",
364                    [(set DPR:$dst, (ARMcneg DPR:$false, DPR:$true, imm:$cc))]>,
365                    RegConstraint<"$false = $dst">;
366
367 def FNEGScc  : ASI<(ops SPR:$dst, SPR:$false, SPR:$true, CCOp:$cc),
368                    "fnegs$cc $dst, $true",
369                    [(set SPR:$dst, (ARMcneg SPR:$false, SPR:$true, imm:$cc))]>,
370                    RegConstraint<"$false = $dst">;